Debian Codegraph @

lib/PGPLOT.pm

raw symbols SCIP
1 package PGPLOT;
2
3 use strict;
4 use warnings;
5 use Exporter;
6 use DynaLoader;
7
8 our $VERSION="2.36";
9
10 our @ISA = qw(Exporter DynaLoader);
11 our @EXPORT = qw( pgarro pgask pgaxis pgband pgbbuf pgbeg pgbegin pgbin pgbox
12 pgcirc pgclos pgconb pgconf pgconl pgcons pgcont pgconx pgctab pgcurs pgcurse pgdraw
13 pgebuf pgend pgenv pgeras pgerrb pgerr1 pgerrx pgerry pgetxt pgfunt pgfunx
14 pgfuny pggray pghi2d pghist pgiden pgimag pglab pglabel pglcur pgldev
15 pglen pgline pgmove pgmtxt pgmtext pgncur pgncurse pgnumb pgolin pgopen pgpage
16 pgadvance pgpanl pgpap pgpaper pgpixl pgpnts pgpoly pgpt pgpt1 pgpoint pgptxt
17 pgptext pgqah pgqcf pgqch pgqci pgqclp pgqcir pgqcol pgqcr pgqcs pgqdt pgqfs pgqhs
18 pgqid pgqinf pgqitf pgqls pgqlw pgqndt pgqpos pgqtbg pgqtxt pgqvp pgqvsz pgqwin
19 pgrect pgrnd pgrnge pgsah pgsave pgunsa pgscf pgsch pgsci pgscir pgsclp pgscr
20 pgscrl pgscrn pgsfs pgshls pgshs pgsitf pgslct pgsls pgslw pgstbg pgsubp pgsvp
21 pgvport pgswin pgwindow pgtbox pgtick pgtext pgupdt pgvect pgvsiz pgvsize
22 pgvstd pgvstand pgwedg pgwnad
23 pggapline pgcolorpnts
24 );
25
26 if($^O =~ /mswin32/i) {
27 local $DynaLoader::dl_dlext = 'xs.dll';
28 bootstrap PGPLOT $VERSION;
29 }
30
31 else {bootstrap PGPLOT $VERSION}
32
33 # return OK status
34
35 1;
36
37 __DATA__
38
39 =head1 NAME
40
41 PGPLOT - allow subroutines in the PGPLOT graphics library to be called from Perl.
42
43 =head1 SYNOPSIS
44
45 use PGPLOT;
46
47 pgbegin(0,"/xserve",1,1);
48 pgenv(1,10,1,10,0,0);
49 pglabel('X','Y','My plot');
50 pgpoint(7,[2..8],[2..8],17);
51
52 # etc...
53
54 pgend;
55
56 =head1 DESCRIPTION
57
58 This module provides an interface to the PGPLOT graphics library. To
59 obtain the library and its manual, see L</OBTAINING PGPLOT>.
60
61 For every PGPLOT function the module provides an equivalent Perl
62 function with the same arguments. Thus the user of the module should
63 refer to the PGPLOT manual to learn all about how to use PGPLOT and
64 for the complete list of available functions. Note that PGPLOT is at
65 its heart a Fortran library, so the documentation describes the
66 Fortran interface.
67
68 Also refer to the extensive set of test scripts (F<t/t*.t>) included
69 in the module distribution for examples of usage of all kinds of
70 PGPLOT routines.
71
72 How the function calls map on to Perl calls is detailed below.
73
74 =head2 Argument Mapping - Simple Numbers And Arrays
75
76 This is more or less as you might expect - use Perl scalars
77 and Perl arrays in place of FORTRAN/C variables and arrays.
78
79 Any FORTRAN REAL/INTEGER/CHARACTER* scalar variable maps to a
80 Perl scalar (Perl doesn't care about the differences between
81 strings and numbers and ints and floats).
82
83 Thus you can say:
84
85 To draw a line to point (42,$x):
86
87 pgdraw(42,$x);
88
89 To plot 10 points with data in Perl arrays C<@x> and C<@y> with plot symbol
90 no. 17. Note the Perl arrays are passed by reference:
91
92 pgpoint(10, \@x, \@y, 17);
93
94 You can also use the old Perl4 style:
95
96 pgpoint(10, *x, *y, 17);
97
98 but this is deprecated in Perl5.
99
100 Label the axes:
101
102 pglabel("X axis", "Data units", $label);
103
104 Draw ONE point, see how when C<N=1> C<pgpoint()> can take a scalar as well as
105 a array argument:
106
107 pgpoint(1, $x, $y, 17);
108
109
110 =head2 Argument Mapping - Images And 2d Arrays
111
112 Many of the PGPLOT commands (e.g. C<pggray>) take 2D arrays as
113 arguments. Several schemes are provided to allow efficient use
114 from Perl:
115
116 =over 4
117
118 =item 1.
119
120 Simply pass a reference to a 2D array, e.g:
121
122 # Create 2D array
123
124 $x=[];
125 for($i=0; $i<128; $i++) {
126 for($j=0; $j<128; $j++) {
127 $$x[$i][$j] = sqrt($i*$j);
128 }
129 }
130 pggray( $x, 128, 128, ...);
131
132 =item 2.
133
134 Pass a reference to a 1D array:
135
136 @x=();
137 for($i=0; $i<128; $i++) {
138 for($j=0; $j<128; $j++) {
139 $x[$i][$j] = sqrt($i*$j);
140 }
141 }
142 pggray( \@x, 128, 128, ...);
143
144 Here @x is a 1D array of 1D arrays. (Confused? - see perldata(1)).
145 Alternatively @x could be a flat 1D array with 128x128 elements, 2D
146 routines such as C<pggray()> etc. are programmed to do the right thing
147 as long as the number of elements match.
148
149 =item 3.
150
151 If your image data is packed in raw binary form into a character string
152 you can simply pass the raw string. e.g.:
153
154 read(IMG, $img, 32768);
155 pggray($img, $xsize, $ysize, ...);
156
157 Here the C<read()> function reads the binary data from a file and the
158 C<pggray()> function displays it as a grey-scale image.
159
160 This saves unpacking the image data in to a potentially very large 2D
161 perl array. However the types must match. The string must be packed as a
162 C<"f*"> for example to use C<pggray>. This is intended as a short-cut for
163 sophisticated users. Even more sophisticated users will want to download
164 the C<PDL> module which provides a wealth of functions for manipulating
165 binary data.
166
167
168 I<Please Note>: As PGPLOT is a Fortran library it expects its images to be
169 be stored in row order. Thus a 1D list is interpreted as a sequence of
170 rows end to end. Perl is similar to C in that 2D arrays are arrays of
171 pointers thus images end up stored in column order.
172
173 Thus using perl multidimensional arrays the coordinate ($i,$j) should be
174 stored in $img[$j][$i] for things to work as expected, e.g:
175
176 $img = [];
177 for $j (0..$nx-1) for $i (0..$ny-1) {
178 $$img[$j][$i] = whatever();
179 }}
180 pggray($$img, $nx, $ny, ...);
181
182 Also PGPLOT displays coordinate (0,0) at the bottom left (this is
183 natural as the subroutine library was written by an astronomer!).
184
185
186 =back
187
188 =head2 Argument Mapping - Function Names
189
190 Some PGPLOT functions (e.g. C<pgfunx>) take functions as callback
191 arguments. In Perl simply pass a subroutine reference or a name,
192 e.g.:
193
194 # Anonymous code reference:
195
196 pgfunx(sub{ sqrt($_[0]) }, 500, 0, 10, 0);
197
198 # Pass by ref:
199
200 sub foo {
201 my $x=shift;
202 return sin(4*$x);
203 }
204
205 pgfuny(\&foo, 360, 0, 2*$pi, 0);
206
207 # Pass by name:
208
209 pgfuny("foo", 360, 0, 2*$pi, 0);
210
211
212 =head2 Argument Mapping - General Handling Of Binary Data
213
214 In addition to the implicit rules mentioned above PGPLOT now provides
215 a scheme for explicitly handling binary data in all routines.
216
217 If your scalar variable (e.g. C<$x>) holds binary data (i.e. 'packed')
218 then simply pass PGPLOT a reference to it (e.g. C<\$x>). Thus one can
219 say:
220
221 read(MYDATA, $wavelens, $n*4);
222 read(MYDATA, $spectrum, $n*4);
223 pgline($n, \$wavelens, \$spectrum);
224
225 This is very efficient as we can be sure the data never gets copied
226 and will always be interpreted as binary.
227
228 Again see the L<PDL> module for sophisticated manipulation of
229 binary data, since it takes great advantage of these facilities.
230 See in particular L<PDL::Graphics::PGPLOT>.
231
232 Be VERY careful binary data is of the right size or your segments
233 might get violated.
234
235 =head1 DEBUGGING
236
237 As of 2.34, there is a C<PGPLOT::set_debugging> function (not
238 exported). It takes an integer argument, and returns the previous value.
239 When any PGPLOT function is called, if that level is >= 1, the name of
240 the function will be printed to standard error.
241
242 =head1 HISTORY
243
244 Originally developed in the olden days of Perl4 (when it was known
245 as 'pgperl' due to the necessity of making a special perl executable)
246 PGPLOT is now a dynamically loadable perl module which interfaces
247 to the FORTRAN graphics library of the same name.
248
249 =head1 OBTAINING PGPLOT
250
251 PGPLOT is a FORTRAN library with C bindings, While the Perl module
252 uses the latter, a FORTRAN compiler is still required to build the library.
253
254 The official library and the manual are available from
255 L<http://astro.caltech.edu/~tjp/pgplot/>
256
257 Building the library using the official distribution is arcane, tedious,
258 and error-prone. Additionally, the official distribution lacks a number
259 of bug fixes and additions provided by the community over the years.
260
261 A modern packaging (using the GNU autotools) of the more up-to-date
262 code base is available from L<https://bitbucket.org/djerius/pgplot-autotool/downloads>
263
264 The packaging has been tested on Linux and Mac OS X.
265
266 Source code is available at either of these sites
267
268 =over
269
270 =item L<https://github.com/djerius/pgplot-autotool>
271
272 =item L<https://bitbucket.org/djerius/pgplot-autotool/src>
273
274 =back
275
276 =head2 Cygwin
277
278 Build the pgplot library and install as above, but with these notes in mind.
279
280 Edit drivers.list to enable the drivers you wish but
281 uncommenting desired drivers by removing the leading ! on the
282 line. Here are the ones used by a previous PDL maintainer:
283
284 $ grep -v '^!' drivers.list
285 LXDRIV 0 /LATEX LaTeX picture environment
286 NUDRIV 0 /NULL Null device (no output) Std F77
287 PPDRIV 1 /PPM Portable Pixel Map file, landscape
288 PPDRIV 2 /VPPM Portable PIxel Map file, portrait
289 PSDRIV 1 /PS PostScript printers, monochrome, landscape Std F77
290 PSDRIV 2 /VPS Postscript printers, monochrome, portrait Std F77
291 PSDRIV 3 /CPS PostScript printers, color, landscape Std F77
292 PSDRIV 4 /VCPS PostScript printers, color, portrait Std F77
293 TTDRIV 5 /XTERM XTERM Tektronix terminal emulator Std F77
294 WDDRIV 1 /WD X Window dump file, landscape
295 WDDRIV 2 /VWD X Window dump file, portrait
296 XWDRIV 1 /XWINDOW Workstations running X Window System C
297 XWDRIV 2 /XSERVE Persistent window on X Window System C
298
299 $ vi sys_cygwin/g77_gcc.conf
300
301 # This diff command shows the lines that need changing
302 $ diff g77_gcc.conf*
303 12c12
304 < XINCL="-I/usr/X11R6/include"
305 ---
306 > XINCL="-I/usr/X11R6.4/include"
307 48c48
308 < FFLAGD="-fno-backslash -I/usr/include"
309 ---
310 > FFLAGD="-fno-backslash"
311 58c58
312 < CFLAGC="-DPG_PPU -O2 -DNOMALLOCH -I. -I/usr/include"
313 ---
314 > CFLAGC="-DPG_PPU -O2 -DNOMALLOCH -I."
315 75c75
316 < LIBS="-L/usr/X11R6/lib -lX11 -lpng -lz"
317 ---
318 > LIBS="-L/usr/X11R6.4/lib -lX11"
319
320 $ ~/pgplot/makemake ~/pgplot cygwin
321 $ make
322 $ make clean
323 $ make cpg
324 $ PGPLOT_DIR="/usr/local/pgplot/"; export PGPLOT_DIR
325
326 Be sure to add C<PGPLOT_DIR> to your environment and add it to
327 your PATH as well.
328
329 NOTE: if problems occur, you may need to C<rebaseall> your libraries.
330
331 =head1 PNG OUTPUT
332
333 If PGPLOT does not write out PNG files, check these things.
334 First, when compiling the pgplot libraries, make sure you uncomment the PNG
335 entries in the F<drivers.list> file. Then when running 'make' you
336 probably got an error like
337
338 C<make: *** No rule to make target `png.h', needed by `pndriv.o'. Stop.>
339
340 To fix this, find the line in the 'makefile' that starts with
341 'pndriv.o:' (it's near the bottom). Change, for example, ./png.h to
342 /usr/include/png.h, if that is where your header files are (you do
343 have the libpng and libz devel packages, don't you?). Do this for all
344 four entries on that line, then go back and run C<make>.
345
346 Second, if you already have the PGPLOT Perl module and PDL installed,
347 you probably tried to write out a PNG file and got fatal error message
348 like:
349
350 C<undefined symbol: png_create_write_struct>
351
352 This is because the PGPLOT Perl module does not automatically link
353 against the png and z libraries. So when you are installing the PGPLOT
354 Perl module (version 2.19) from CPAN, don't do C<install PGPLOT>, but
355 just do C<get PGPLOT>. Then exit from CPAN and manually install
356 PGPLOT, calling the makefile thusly:
357
358 C<perl Makefile.PL EXLIB=png,z EXDIR=/usr/lib>
359
360 assuming that there exist files such as /usr/lib/libpng.so.*,
361 /usr/lib/libz.so.*. Then do the standard C<make;make test;make
362 install;> sequence. Now you can write png files from PDL!
363
364 =head1 AUTHORS
365
366 Karl Glazebrook E<lt>[email protected]<gt>