<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#
# format_temp.pl --&gt; extracts apv temperature (cf. format_apv.sh)

# ****************
# * Declarations *
# ****************

# Number of days in month of normal year &amp; leap year

    @month1 = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
    @month2 = ( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );


# *************
# * Main Loop *
# *************

MainLoop:

    while ( defined( $line = &lt;STDIN&gt; ) ) {

# Get next upload of data

        next if ( $line !~ /Upload/ );

# Extract number of samples and starting scan number

        @fields = split( /\s+/, $line );
        $nfields = @fields;
        next if ( $nfields != 11 );

        $nsamples = @fields[ 2 ];
        $scan     = @fields[ 10 ];

# Get date &amp; time for first scan from next data line

        $line = &lt;STDIN&gt;;
        @fields = split( /\s+/, $line );
        $nfields = @fields;
        next if ( $nfields != 8 );

        $time = @fields[ 5 ];
        $date = @fields[ 6 ];

        @fields = split( /\//, $date );
        $month = @fields[ 0 ];
        $day   = @fields[ 1 ];
        $year  = @fields[ 2 ];

        @fields = split( /:/, $time );
        $hour = @fields[ 0 ];
        $min  = @fields[ 1 ];
        $sec  = @fields[ 2 ];

# If not first scan, increment time to match scan

        if ( $scan == 0 ) {
            $line = &lt;STDIN&gt;;
            $scan = 1;
        }
        while ( $scan &gt; 1 ) {
            inc_time();
            $scan--;
        }

# Skip blank line

        $line = &lt;STDIN&gt;;

# Read each data line

        for ( $i = 0; $i &lt; $nsamples; $i++ ) {

            $data = &lt;STDIN&gt;;
            chomp( $data );
            goto MainLoop if ( length( $data) != 28 );
            goto MainLoop if ( $data !~ /\./ );

# Ignore data if battery voltage &lt; 10 volts

            @fields = split( /\s+/, $data );
            $battery = @fields[ 1 ];
            if ( $battery &gt;= 10 ) {

# Write out data line appending time information

                $month = "0" . $month if ( length( $month ) &lt; 2 );
                $day   = "0" . $day   if ( length( $day )   &lt; 2 );
                $hour  = "0" . $hour  if ( length( $hour )  &lt; 2 );
                $min   = "0" . $min   if ( length( $min )   &lt; 2 );
                $sec   = "0" . $sec   if ( length( $sec )   &lt; 2 );

                print ( $year, "/", $month, "/", $day, " ",
                        $hour, ":", $min,   ":", $sec, " ",
                        $data, "\n" );

            }

# Increment time by one second

            inc_time();
            
        }
    }


# ******************************
# * Increment Time by 1 Second *
# ******************************

sub inc_time {
    $sec++;
    if ( $sec &gt;= 60 ) {
        $sec = 0;
        $min++;
        if ( $min &gt;= 60 ) {
            $min = 0;
            $hour++;
            if ( $hour &gt;= 24 ) {
                $hour = 0;
                $day++;
                if ( ( $year % 4 ) != 0 ) {
                    $ndays = @month1[ $month - 1 ];
                } else {
                    $ndays = @month2[ $month - 1 ];
                }
                if ( $day &gt; $ndays ) {
                    $day = 1;
                    $month++;
                    if ( $month &gt; 12 ) {
                        $month = 1;
                        $year++;
                    }
                }
            }
        }
    }
}

</pre></body></html>