nickschurch has asked for the wisdom of the Perl Monks concerning the following question:

I've written a small perl script to create a series of .gif files, from a series of text datafiles, using PGPLOT. The code is shown below. It takes the 100 text files and turns them into 100 .gif images called 'frame_xxx.gif' from 001 to 100. These then form the frames of an animated gif.

The code sucessfully creates frame 1 and frames 3-100 as files in the $animdir directory (so it looks like its working), but for frame 2 it creates the gif file in the current directory with a filename of pgplot10922.gif and creates an empty frame_002.gif file in the $animdir directory. This is accompanied by the onscreen message "PGPLOT, Writing new GIF image as: pgplot10922.gif"

I'm very confused. This file is correct, but not called the right thing or in the right place! And why does it work for all the other frames but not that one? Any ideas?
# -------------- System variables my $currentdir = getcwd(); my $logdir = "Logs"; my $outdir = "Windoutput"; my $specdir = "Specfiles"; my $animdir = "Animfiles"; # -------------- End system variables # -------------- Main program variables my $framenumber = 1; my $frameplot; my $emin=300; my $emax=13000; my $xmin = log10($emin/1000); my $xmax = log10($emax/1000); my $ymin = log10(6E2); my $ymin2 = log10(2E4); my $ymax = log10(6E6); my $filename; # -------------- Prompted Variables print " Please enter number of frames (default = 100): "; my $nframes = <STDIN>; chomp $nframes; $nframes = 100 if ($nframes eq ""); print " Processing frame:\n "; # -------------- Main program loop until ($framenumber>$nframes) { print "${framenumber}: "; $filename = "$animdir/frame_00${framenumber}.gif/gif" if ($framenu +mber<10); $filename = "$animdir/frame_0${framenumber}.gif/gif" if (($framenu +mber>9) and ($framenumber<100)); $filename = "$animdir/frame_${framenumber}.gif/gif" if $framenumbe +r>99; print "$filename\n"; $frameplot = PDL::Graphics::PGPLOT::Window->new(Device => $filenam +e, AxisColour => 'black', Font => 'Roman', WindowXSize => 8 , WindowY +Size => 9.23, HardLW => 4); $frameplot = PDL::Graphics::PGPLOT::Window->new(Device => '/xs', A +xisColour => 'black', Font => 'Roman', WindowXSize => 8 , WindowYSize + => 9.23) if ($debug_level==1); # Prepare space for transmitted spectrum plot $frameplot->env($xmin,$xmax,$ymin,$ymax, { PlotPosition => [0.06, 0.99, 0.06, 0.639], Charsize => 0.8, Axis => 'LogXY', Xtitle => 'Energy (keV)', Ytitle => 'E L\dE\u [erg(erg/s/erg)]', }); my ($energy, $trans) = rcols "$animdir/${framenumber}_trans_spect. +txt", {LINES => '4:-1'}; my ($junk, $emit) = rcols "$animdir/${framenumber}_emit_spect.txt" +, {LINES => '4:-1'}; my ($incenergy, $inclumin) = rcols "${xscortpath}/powerlaw.dat", { +LINES => '2:-1'}; my $plotmask = which(($incenergy>$emin) & ($incenergy<$emax)); my $x = $incenergy->dice($plotmask); my $y = $inclumin->dice($plotmask); $frameplot->line(log10($x/1000), log10($y*1.60217646E-12*$x), {Col +our => 'black'}); $plotmask = which(($energy>$emin) & ($energy<$emax)); $x = $energy->dice($plotmask); $y = $trans->dice($plotmask); $frameplot->line(log10($x/1000), log10($y*1.60217646E-12*$x), {Col +our => 'blue'}); $y = $emit->dice($plotmask); $frameplot->line(log10($x/1000), log10($y*1.60217646E-12*$x), {Col +our => 'red'}); $frameplot->env($xmin,$xmax,$ymin2,$ymax, { PlotPosition => [0.06, 0.99, 0.639, 0.99], Charsize => 0.8, Axis => ['BCSTL','BCNSTL'], Ytitle => 'E L\dE\u [erg(erg/s/erg)]', }); $plotmask = which(($incenergy>$emin) & ($incenergy<$emax)); $x = $incenergy->dice($plotmask); $y = $inclumin->dice($plotmask); $frameplot->line(log10($x/1000), log10($y*1.60217646E-12*$x), {Col +our => 'black'}); $y = ($emit+$trans)->dice($plotmask); $frameplot->line(log10($x/1000), log10($y*1.60217646E-12*$x), {Col +our => 'dark green'}); if ($debug_level==1) { print "Press return to continue..."; my $pause = <STDIN>; } $frameplot->close(); $framenumber++; }

Replies are listed 'Best First'.
Re: PGPLOT perl module weirdness...
by moritz (Cardinal) on Jan 30, 2008 at 10:36 UTC
    I have no solution to your problem, but one piece of code struck me:
    $filename = "$animdir/frame_00${framenumber}.gif/gif" if ($framenu +mber<10); $filename = "$animdir/frame_0${framenumber}.gif/gif" if (($framenu +mber>9) and ($f +ramenumber<100)); $filename = "$animdir/frame_${framenumber}.gif/gif" if $framenumbe +r>99;
    There is a much simpler implementation for that:
    $filename = sprintf "%s/frame_%03d.gif/gif", $animdir, $framenumber +;
Re: PGPLOT perl module weirdness...
by zentara (Cardinal) on Jan 30, 2008 at 14:58 UTC
    If you havn't already, you should ask this on the PDL maillist It's very active with users familiar with PGPLOT.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      I haven't put it on the PDL mail-list - I didn't even know there was one! Thanks for pointing me to it.

      Also, Thanks moritz for your suggestion. Thats a much better way than I was doing it. It works fine, but I'm still getting the same problem so it not fixed that. *sigh*