<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env perl

# ========================================================================
# pppPlot.pl - plot BNC's PPP results using gnuplot
# ========================================================================
#
# Plot metrics:
#    - NEU displacements w.r.t. coordinates in Crd file
#    - A-priori + correction values of tropospheric zenith delay in [m],
#    - Receiver clock error and offsets in [m],
#    - Elevations, given per satellite
#    - Ambiguities, given per satellite
#    - Ionosphere Delay [m],
#    - Receiver Bias [m]
#    - Code and phase residuals in [m],
#
# Author  : Andrea Stuerze
# Revision: $Header: trunk/BNC/scripts/pppPlot.pl 10644 2025-03-20 14:58:13Z stuerze $
# Changes :
# ========================================================================

# Uses
use strict;
use warnings;

BEGIN {
    use FindBin qw($Bin);
    use lib "$Bin";
}

use diagnostics;
use PDL;
use FindBin qw($Bin);
use Getopt::Long;
use Chart::Gnuplot;
use Data::Dumper qw(Dumper);
use File::Basename;
use Date::Manip;
use Log::Log4perl qw(:easy);
use PDF::API2;

use Bnc;
use Common;

use constant {
               mm   =&gt; 25.4 / 72,
               inch =&gt; 1 / 72,
               pt   =&gt; 1,
};    # There are 72 postscript points in an inch and there are 25.4 millimeters in an inch.


# Logging
Log::Log4perl-&gt;easy_init(
    {

        #file   =&gt; "plotPPP.log",
        layout =&gt; '%d [%c l%L] %p: %m%n',
        level  =&gt; $TRACE
    }
);

# Options
my ($prog)    = fileparse($0);
my $help      = 0;
my @plotTypes = ();
my @logFiles  = ();
my $sampling  = 1;

GetOptions(
            'help'        =&gt; \$help,
            'plotTypes=s' =&gt; \@plotTypes,
            'logFiles=s'  =&gt; \@logFiles,
            'sampling=s'  =&gt; \$sampling,
);

HELP_MESSAGE() if $help;
@plotTypes = qw(NEU) unless (@plotTypes);
@plotTypes = map {uc} split ( /[, ]/, join ( ',', @plotTypes ) );
@logFiles  = split ( /[, ]/, join ( ',', @logFiles ) );
unless (@logFiles) { ERROR "logfiles missing"; HELP_MESSAGE() }
DEBUG("\n       plotTpes: @plotTypes\n       logfiles: @logFiles\n       sampling:  $sampling");

# -----------------------------------------------------------------------------
# Generate data sets for gnuplot
# -----------------------------------------------------------------------------
# for pdf gerneration
my ( $png, $page, $headline, $headline_text );
my $y0 = 180 / mm;
my ( $x, $y, $width, $height ) = ( 40 / mm, $y0, 130 / mm, 80 / mm );
my $dy = $height + 10 / mm;

# Loop over logfiles
foreach my $file (@logFiles) {
    DEBUG "Parse logfile $file";

    # -----------------------------------------------------------------------------
    # Create pdf for plot results
    # -----------------------------------------------------------------------------
    my ( $inputFilename, $inputDir, $inputSuffix ) = fileparse( $file, '\..*' );
    my $pdf_name = sprintf ( "%s.pdf", $inputFilename );
    my $pdf      = PDF::API2-&gt;new( -file =&gt; "$inputDir$pdf_name" );
    my $font1    = $pdf-&gt;corefont('Helvetica-Bold');

    # -----------------------------------------------------------------------------
    # Read logfile
    # -----------------------------------------------------------------------------
    my ( $station, $file ) = Bnc::parsePPPLogfile( $file, $sampling );
    my $EPOCH       = $file-&gt;{'EPOCH'};
    my %RECCLK        = %{ $file-&gt;{'RECCLK'} };
    my %AMB            = %{ $file-&gt;{'AMB'} };
    my %RES            = %{ $file-&gt;{'RES'} };
    my %ELE            = %{ $file-&gt;{'ELE'} };
    my %ION            = %{ $file-&gt;{'ION'} };
    my %BIA            = %{ $file-&gt;{'BIA'} };

    # -----------------------------------------------------------------------------
    # RMS computation
    # -----------------------------------------------------------------------------
    my ( $mean, $prms, $median, $min, $max, $adev, $rms_n, $rms_e, $rms_u, $rms_trp );
    my ( $n, $e, $u, $trp, $str_rms_n, $str_rms_e, $str_rms_u, $str_rms_trp );
    $n = pdl( $file-&gt;{'N'} );
    ( $mean, $prms, $median, $min, $max, $adev, $rms_n ) = stats($n);
    $e = pdl( $file-&gt;{'E'} );
    ( $mean, $prms, $median, $min, $max, $adev, $rms_e ) = stats($e);
    $u = pdl( $file-&gt;{'U'} );
    ( $mean, $prms, $median, $min, $max, $adev, $rms_u ) = stats($u);
    $trp = pdl( $file-&gt;{'TRP'} );
    ( $mean, $prms, $median, $min, $max, $adev, $rms_trp ) = stats($trp);
    $str_rms_n   = sprintf ( " %.2f ", $rms_n );
    $str_rms_e   = sprintf ( " %.2f ", $rms_e );
    $str_rms_u   = sprintf ( " %.2f ", $rms_u );
    $str_rms_trp = sprintf ( " %.2f ", $rms_trp );
    DEBUG("RMS: North: $str_rms_n, East: $str_rms_e, Up: $str_rms_u, TRP: $str_rms_trp");

    # -----------------------------------------------------------------------------
    # Plot several data sets
    # -----------------------------------------------------------------------------
    my $dataset;
    ######### NEU #####################
    DEBUG "Plot NEU";
    $page = $pdf-&gt;page();
    $page-&gt;mediabox('A4');
    $headline      = sprintf ( "PPP results for station %s", $station );
    $headline_text = $page-&gt;text;
    $headline_text-&gt;font( $font1, 11 / pt );
    $headline_text-&gt;translate( 15 / mm, 280 / mm );
    $headline_text-&gt;text($headline);
    $y = $y0;
    my $pngNameNEU  = sprintf ( "%s_NEU.png", $station );
    my $chartNEU = newChart($station);
    $chartNEU-&gt;set( output =&gt; $pngNameNEU);
    $chartNEU-&gt;set( ylabel =&gt; "Displacements [m]", yrange =&gt; [ " -0.5 ", " 0.5 " ] );

    #y2label =&gt; "Number of Satellites [-]", y2range =&gt; [" 0 ", " 20 "], y2tics =&gt; 'on',

    my $dataN = Chart::Gnuplot::DataSet-&gt;new(
                                              xdata   =&gt; $EPOCH,
                                              ydata   =&gt; $file-&gt;{'N'},
                                              title   =&gt; "Displacements N, RMS + -$str_rms_n m",
                                              timefmt =&gt; '%s',
                                              style   =&gt; "linespoints",
    );
    my $dataE = Chart::Gnuplot::DataSet-&gt;new(
                                              xdata   =&gt; $EPOCH,
                                              ydata   =&gt; $file-&gt;{'E'},
                                              title   =&gt; "Displacements E, RMS + -$str_rms_e m",
                                              timefmt =&gt; '%s',
                                              style   =&gt; "linespoints",
    );
    my $dataU = Chart::Gnuplot::DataSet-&gt;new(
                                              xdata   =&gt; $EPOCH,
                                              ydata   =&gt; $file-&gt;{'U'},
                                              title   =&gt; "Displacements U, RMS + -$str_rms_u m",
                                              timefmt =&gt; '%s',
                                              style   =&gt; "linespoints",
    );
    my @datasets = ( $dataN, $dataE, $dataU );
    $chartNEU-&gt;plot2d(@datasets);

    $png = $page-&gt;gfx();
    LOGDIE("could not find image file: $!\n") unless -e $pngNameNEU;
    $png-&gt;image( $pdf-&gt;image_png($pngNameNEU), $x, $y, $width, $height );    #print "y= : $y \n"

    ######### TRP #####################
    if ( grep ( $_ eq "ALL", @plotTypes ) ) {
        DEBUG "Plot TRP";
        my $pngNameTRP  = sprintf ( "%s_TRP.png", $station );
        my $chartTRP = newChart($station);
        $chartTRP-&gt;set( output =&gt; $pngNameTRP);
        $chartTRP-&gt;set( ylabel =&gt; "Tropospheric Delay [m]", yrange =&gt; [ " 1.0 ", " 3.0 " ] );

        my $dataTRP = Chart::Gnuplot::DataSet-&gt;new(
                                                    xdata   =&gt; $EPOCH,
                                                    ydata   =&gt; $file-&gt;{'TRP'},
                                                    title   =&gt; "Tropospheric Delay, RMS + -$str_rms_trp m",
                                                    timefmt =&gt; '%s',
                                                    style   =&gt; "points",
        );
        $chartTRP-&gt;plot2d($dataTRP);
        $y = $y - $dy;

        if ( $y &lt; 30 / mm ) {
            $page = $pdf-&gt;page();
            $page-&gt;mediabox('A4');
            $y = $y0;
        }
        $png = $page-&gt;gfx();
        LOGDIE("could not find image file: $!\n") unless -e $pngNameTRP;
        $png-&gt;image( $pdf-&gt;image_png($pngNameTRP), $x, $y, $width, $height );

        ######### RECCLK #####################
        DEBUG "Plot Receiver Clocks";
        $page = $pdf-&gt;page();
        $page-&gt;mediabox('A4');
        $y             = $y0 + $dy;
        $headline      = sprintf ( "Receiver Clocks for station %s", $station );
        $headline_text = $page-&gt;text;
        $headline_text-&gt;font( $font1, 11 / pt );
        $headline_text-&gt;translate( 15 / mm, 280 / mm );
        $headline_text-&gt;text($headline);

        my $chartRECCLK = newChart($station);
        $chartRECCLK-&gt;set( legend =&gt; { position =&gt; "outside right" } );
        my @datasets = ();                                                # init datasets
        my $pngNameRECCLK  = sprintf ( "%s_RECCLK.png", $station);
            $chartRECCLK-&gt;set( output =&gt; $pngNameRECCLK);
            $chartRECCLK-&gt;set( ylabel =&gt; "Receiver Clocks [m]" );
            # SYSTEM
            foreach my $key_sys ( sort keys %RECCLK ) {

                $dataset = Chart::Gnuplot::DataSet-&gt;new(
                    xdata   =&gt; \@{ $RECCLK{$key_sys}{EPOCH} },         # array of epochs
                    ydata   =&gt; \@{ $RECCLK{$key_sys}{DATA} },          # array of elevations of one satellite
                    title   =&gt; "$key_sys",
                    timefmt =&gt; '%s',

                    #style   =&gt; "points",
                    style =&gt; "points",
                );
                push ( @datasets, $dataset );
            }
            $chartRECCLK-&gt;plot2d(@datasets);

            # system ("display $pngName&amp;");
            $y = $y - $dy;
            if ( $y &lt; 30 / mm ) {
                $page = $pdf-&gt;page();
                $page-&gt;mediabox('A4');
                $y = $y0;
            }
            $png = $page-&gt;gfx();
            die ("could not find image file: $!") unless -e $pngNameRECCLK;
            $png-&gt;image( $pdf-&gt;image_png($pngNameRECCLK), $x, $y, $width, $height );

        ######### ELE #####################
        DEBUG "Plot Elevations";
        $page = $pdf-&gt;page();
        $page-&gt;mediabox('A4');
        $y             = $y0 + $dy;
        $headline      = sprintf ( "Satellite Elevations for station %s", $station );
        $headline_text = $page-&gt;text;
        $headline_text-&gt;font( $font1, 11 / pt );
        $headline_text-&gt;translate( 15 / mm, 280 / mm );
        $headline_text-&gt;text($headline);

        my $chartELE = newChart($station);
        $chartELE-&gt;set( legend =&gt; { position =&gt; "outside right" } );

        # SYSTEM #print Dumper \%ELE;
        foreach my $key_sys ( sort keys %ELE ) {

            # print "$key_sys \n";# print Dumper $ELE{$key_sys};
            my @datasets = ();                                                # init datasets
            my $pngNameELE  = sprintf ( "%s_ELE_%s.png", $station, $key_sys );
            $chartELE-&gt;set( output =&gt; $pngNameELE);
            $chartELE-&gt;set( ylabel =&gt; "Elevation [°]", yrange =&gt; [ " 0.0 ", " 90.0 " ] );

            # SATELLITE
            foreach my $key_sat ( sort keys %{ $ELE{$key_sys} } ) {

                # print "$key_sat = $ELE{$key_sys}{$key_sat} \n";
                $dataset = Chart::Gnuplot::DataSet-&gt;new(
                    xdata   =&gt; \@{ $ELE{$key_sys}{$key_sat}{EPOCH} },         # array of epochs
                    ydata   =&gt; \@{ $ELE{$key_sys}{$key_sat}{DATA} },          # array of elevations of one satellite
                    title   =&gt; "$key_sat",
                    timefmt =&gt; '%s',

                    #style   =&gt; "points",
                    style =&gt; "points",
                );
                push ( @datasets, $dataset );
            }
            $chartELE-&gt;plot2d(@datasets);

            # system ("display $pngName&amp;");
            $y = $y - $dy;
            if ( $y &lt; 30 / mm ) {
                $page = $pdf-&gt;page();
                $page-&gt;mediabox('A4');
                $y = $y0;
            }
            $png = $page-&gt;gfx();
            die ("could not find image file: $!") unless -e $pngNameELE;
            $png-&gt;image( $pdf-&gt;image_png($pngNameELE), $x, $y, $width, $height );
        }

        ######### AMB #####################
        DEBUG "Plot Ambiguities";
        $page = $pdf-&gt;page();
        $page-&gt;mediabox('A4');
        $y             = $y0 + $dy;
        $headline      = sprintf ( "Ambiguities for station %s", $station );
        $headline_text = $page-&gt;text;
        $headline_text-&gt;font( $font1, 11 / pt );
        $headline_text-&gt;translate( 15 / mm, 280 / mm );
        $headline_text-&gt;text($headline);

        # AMBIGUITY_TYPE #print Dumper \%AMB;
        foreach my $key_ambType (%AMB) {    #print "$key_ambType \n";
            foreach my $key_sys ( sort keys %{ $AMB{$key_ambType} } ) {

                #print "$key_sys \n"; print Dumper $AMB{$key_ambType};
                my ( @datasets_amb, @datasets_epo );    # init datasets
                my $pngNameAMB = sprintf ( "%s_AMB_%s_%s.png", $station, $key_ambType, $key_sys );
                my $pngNameEPO = sprintf ( "%s_EPO_%s_%s.png", $station, $key_ambType, $key_sys );
                my $chartAMB = Chart::Gnuplot-&gt;new(
                    output   =&gt; $pngNameAMB,
                    terminal =&gt; 'png',
                    title    =&gt; $station,
                    ylabel   =&gt; "Ambiguities $key_ambType [m]",

                    # yrange =&gt; [" 0.0 ", " 90.0 "],
                    xlabel   =&gt; "Time [h]",
                    timeaxis =&gt; 'x',
                    xtics    =&gt; { labelfmt =&gt; '%H:%M', rotate =&gt; '-270', },
                    legend   =&gt; { position =&gt; "outside right", },
                    grid     =&gt; 'on',
                );
                my $chartEPO = Chart::Gnuplot-&gt;new(
                    output   =&gt; $pngNameEPO,
                    terminal =&gt; 'png',
                    title    =&gt; $station,
                    ylabel   =&gt; "Number of Epochs $key_ambType [-]",

                    # yrange =&gt; [" 0.0 ", " 90.0 "],
                    xlabel   =&gt; "Time [h]",
                    timeaxis =&gt; 'x',
                    xtics    =&gt; { labelfmt =&gt; '%H:%M', rotate =&gt; '-270', },
                    legend   =&gt; { position =&gt; "outside right", },
                    grid     =&gt; 'on',
                );

                # SATELLITE
                foreach my $key_sat ( sort keys %{ $AMB{$key_ambType}{$key_sys} } ) {

                    #print "$key_sat = $AMB{$key_ambType}{$key_sys}{$key_sat} \n";
                    # ambiguities
                    my $dataset_amb = Chart::Gnuplot::DataSet-&gt;new(
                        xdata =&gt; $AMB{$key_ambType}{$key_sys}{$key_sat}{EPOCH},  # array of epochs
                        ydata =&gt; $AMB{$key_ambType}{$key_sys}{$key_sat}{DATA},   # array of ambiguities of one satellite
                        title =&gt; "$key_sat",
                        timefmt =&gt; '%s',
                        style   =&gt; "points",

                        #style   =&gt; "points",
                    );
                    push ( @datasets_amb, $dataset_amb );

                    # number of epochs used for ambiguity
                    my $dataset_epo = Chart::Gnuplot::DataSet-&gt;new(
                        xdata =&gt; $AMB{$key_ambType}{$key_sys}{$key_sat}{EPOCH},  # array of epochs
                        ydata =&gt; $AMB{$key_ambType}{$key_sys}{$key_sat}{NUMEPO}, # array of ambiguities of one satellite
                        title =&gt; "$key_sat",
                        timefmt =&gt; '%s',

                        #style   =&gt; "points",
                        style =&gt; "points",
                    );
                    push ( @datasets_epo, $dataset_epo );
                }

                # ambiguities
                $chartAMB-&gt;plot2d(@datasets_amb);

                # system ("display $pngName_amb&amp;");
                $y = $y - $dy;
                if ( $y &lt; 30 / mm ) {
                    $page = $pdf-&gt;page();
                    $page-&gt;mediabox('A4');
                    $y = $y0;
                }
                $png = $page-&gt;gfx();
                LOGDIE("could not find image file: $!\n") unless -e $pngNameAMB;
                $png-&gt;image( $pdf-&gt;image_png($pngNameAMB), $x, $y, $width, $height );

                # number of epochs used for ambiguity
                $chartEPO-&gt;plot2d(@datasets_epo);

                # system ("display $pngName_epo&amp;");
                $y = $y - $dy;
                if ( $y &lt; 30 / mm ) {
                    $page = $pdf-&gt;page();
                    $page-&gt;mediabox('A4');
                    $y = $y0;
                }
                $png = $page-&gt;gfx();
                LOGDIE("could not find image file $pngNameEPO: $!\n") unless -e $pngNameEPO;
                $png-&gt;image( $pdf-&gt;image_png($pngNameEPO), $x, $y, $width, $height );
            }
        }

        ######### ION #####################
        if ( grep ( $_ eq "ALL", @plotTypes ) ) {
            DEBUG "Plot ION";
            $page = $pdf-&gt;page();
            $page-&gt;mediabox('A4');
            $y             = $y0 + $dy;
            $headline      = sprintf ( "Ionosphere Delay for station %s", $station );
            $headline_text = $page-&gt;text;
            $headline_text-&gt;font( $font1, 11 / pt );
            $headline_text-&gt;translate( 15 / mm, 280 / mm );
            $headline_text-&gt;text($headline);

            my $chartION = newChart($station);
            $chartION-&gt;set( ylabel =&gt; "Ionophere Delay [m]" );
            $chartION-&gt;set( legend =&gt; { position =&gt; "outside right" } );

            # SYSTEM
            foreach my $ksys ( sort keys %ION ) {    #print "$key_sys \n"; #print Dumper $ION{$key_sys};
                my @datasets;                        # init datasets
                my $pngNameION = sprintf ( "%s_ION_%s.png", $station, $ksys );
                $chartION-&gt;set( output =&gt; $pngNameION);

                # SATELLITE
                foreach my $sat ( sort keys %{ $ION{$ksys} } ) {    #print "$key_sat = $ION{$key_sys}{$key_sat} \n";
                    my $dataset = Chart::Gnuplot::DataSet-&gt;new(
                        xdata   =&gt; $ION{$ksys}{$sat}{EPOCH},        # array of epochs
                        ydata   =&gt; $ION{$ksys}{$sat}{DATA},         # array of ionvations of one satellite
                        title   =&gt; "$sat",
                        timefmt =&gt; '%s',

                        #style   =&gt; " points ",
                        style =&gt; "points",
                    );
                    push ( @datasets, $dataset );
                }

                $chartION-&gt;plot2d(@datasets);                       #system ("display $pngName&amp;");
                $y = $y - $dy;
                if ( $y &lt; 30 / mm ) {
                    $page = $pdf-&gt;page();
                    $page-&gt;mediabox('A4');
                    $y = $y0;
                }
                $png = $page-&gt;gfx();
                die ("could not find image file: $!") unless -e $pngNameION;
                $png-&gt;image( $pdf-&gt;image_png($pngNameION), $x, $y, $width, $height );
            }
        }

        ######### BIAS #####################
        if ( grep ( $_ eq "ALL", @plotTypes ) ) {
            DEBUG "Plot BIAS";
            $page = $pdf-&gt;page();
            $page-&gt;mediabox('A4');
            $y             = $y0 + $dy;
            $headline      = sprintf ( "Receiver Biases for station %s", $station );
            $headline_text = $page-&gt;text;
            $headline_text-&gt;font( $font1, 11 / pt );
            $headline_text-&gt;translate( 15 / mm, 280 / mm );
            $headline_text-&gt;text($headline);

            my $chartBIAS = newChart($station);
            $chartBIAS-&gt;set( legend =&gt; { position =&gt; "outside right" } );

            # BIAS_TYPE   #print Dumper \%BIA;
            foreach my $key_biasType ( sort keys %BIA ) {    #print "key_biasType: $key_biasType \n";
                foreach my $key_sys ( sort keys %{ $BIA{$key_biasType} } ) {

                    #print "key_sys: $key_sys \n"; #print Dumper $BIA{$key_biasType};
                    my @datasets;                            # init datasets
                    my $pngNameBIA = sprintf ( "%s_BIAS_%s_%s.png", $station, $key_biasType, $key_sys );
                    $chartBIAS-&gt;set( output =&gt; $pngNameBIA);
                    $chartBIAS-&gt;set( ylabel =&gt; "Receiver Bias $key_biasType [m]" );

                    my $dataset =
                      Chart::Gnuplot::DataSet-&gt;new(
                                                    xdata   =&gt; $BIA{$key_biasType}{$key_sys}{EPOCH},
                                                    ydata   =&gt; $BIA{$key_biasType}{$key_sys}{DATA},
                                                    title   =&gt; "$key_sys",
                                                    timefmt =&gt; '%s',
                                                    style   =&gt; "points",
                      );
                    push ( @datasets, $dataset );

                    $chartBIAS-&gt;plot2d(@datasets);
                    $y = $y - $dy;
                    if ( $y &lt; 30 / mm ) {
                        $page = $pdf-&gt;page();
                        $page-&gt;mediabox('A4');
                        $y = $y0;
                    }
                    $png = $page-&gt;gfx();
                    die ("could not find image file: $!") unless -e $pngNameBIA;
                    $png-&gt;image( $pdf-&gt;image_png($pngNameBIA), $x, $y, $width, $height );
                }
            }
        }

        ######### RES #####################
        DEBUG "Plot Residuals";
        $page = $pdf-&gt;page();
        $page-&gt;mediabox('A4');
        $y             = $y0 + $dy;
        $headline      = sprintf ( "Residuals for station %s", $station );
        $headline_text = $page-&gt;text;
        $headline_text-&gt;font( $font1, 11 / pt );
        $headline_text-&gt;translate( 15 / mm, 280 / mm );
        $headline_text-&gt;text($headline);

        my $chartRES = newChart($station);
        $chartRES-&gt;set( legend =&gt; { position =&gt; "outside right" } );

        # RESIDUAL_TYPE   #print Dumper \%RES;
        foreach my $key_resType ( sort keys %RES ) {    #print "key_resType: $key_resType \n";
                                                        #SYSTEM
            foreach my $key_sys ( sort keys %{ $RES{$key_resType} } ) {

                #print "key_sys: $key_sys \n"; #print Dumper $RES{$key_resType};
                my @datasets;
                my $pngNameRES = sprintf ( "%s_RES_%s_%s.png", $station, $key_resType, $key_sys );
                $chartRES-&gt;set( output =&gt; $pngNameRES);
                $chartRES-&gt;set( ylabel =&gt; "Residuals $key_resType [m]" );

                if ( $key_resType =~ /^c/ ) {
                    $chartRES-&gt;set( yrange =&gt; [ " -6.0 ", " 6.0 " ] );
                }
                elsif ( $key_resType =~ /^l/ ) {
                    $chartRES-&gt;set( yrange =&gt; [ " -0.06 ", " 0.06 " ] );
                }

                elsif ( $key_resType =~ /^GIM/ ) {
                    $chartRES-&gt;set( yrange =&gt; [ " -6.0 ", " 6.0 " ] );
                }

                # SATELLITE
                foreach my $key_sat ( sort keys %{ $RES{$key_resType}{$key_sys} } ) {

                    #print "$key_sat = $RES{$key_resType}{$key_sys}{$key_sat} \n";
                    $dataset = Chart::Gnuplot::DataSet-&gt;new(
                        xdata   =&gt; $RES{$key_resType}{$key_sys}{$key_sat}{EPOCH},  # array of epochs
                        ydata   =&gt; $RES{$key_resType}{$key_sys}{$key_sat}{DATA},   # array of residuals of one satellite
                        title   =&gt; "$key_sat",
                        timefmt =&gt; '%s',
                        style =&gt; "points",
                    );
                    push ( @datasets, $dataset );
                }
                $chartRES-&gt;plot2d(@datasets);
                $y = $y - $dy;
                if ( $y &lt; 30 / mm ) {
                    $page = $pdf-&gt;page();
                    $page-&gt;mediabox('A4');
                    $y = $y0;
                }
                $png = $page-&gt;gfx();
                LOGDIE("could not find image file: $!\n") unless -e $pngNameRES;
                $png-&gt;image( $pdf-&gt;image_png($pngNameRES), $x, $y, $width, $height );
            }
        }
    }    # end if ALL @plotTypes

    $pdf-&gt;save();
    $pdf-&gt;end();

    system ("rm *.png");
    if (Common::amInteractiv ) {
      system ("evince $inputDir/$pdf_name");
    }
}    # -----  next logfile  -----

# newChart returns a default chart.
sub newChart {
    my $title = shift;
    return Chart::Gnuplot-&gt;new(
                                terminal =&gt; 'png',
                                title    =&gt; $title,
                                xlabel   =&gt; "Time [h]",
                                timeaxis =&gt; 'x',
                                xtics    =&gt; { labelfmt =&gt; '%H:%M', rotate =&gt; '-270' },
                                grid     =&gt; 'on',
    );
}

sub HELP_MESSAGE {
    print &lt;&lt;EOI_HILFE;
$prog - plot BNC's PPP results using gnuplot

USAGE:
  $prog [OPTIONS]

OPTIONS:
  -p, --plotTypes    ALL or NEU (default)
  -l, --logFiles     comma separated list of BNC's PPP logfiles
  -s, --sampling     sampling interval in seconds for the logfile data (default: 1); for a daily logfile &lt;30&gt; seconds should be usefull
  -h, --help         show help contents

EXAMPLES:
  $prog --plotTypes ALL -s 30 -l /path/to/FFMJ186730.ppp

2021 andrea.stuerze\@bkg.bund.de
EOI_HILFE
    exit;
}
</pre></body></html>