#!/usr/bin/perl
#-------------------------------------------------------------------------------
# script : CheckStationLogs.pl
#
# usage : CheckStationLogs.pl [-h] -l StationLogsDirectory -r ReferencesDirectory [-c CurrentLogDirectory] [-s Network]
#
# Author : Royal Observatory of Belgium
#
# Perl version : 5
#
# Disclaimer : No responsibility is accepted by or on behalf of the ROB for any script errors.
#              The ROB will under no circumstances be held liable for any direct or indirect consequences,
#              nor for any damages that may occur from the use of this script (or any required other script).
#
# Purpose : Validate information in the station log files available from a directory (-l) using
#           mandatory reference files (-r) (antenna.gra, rcvr_ant.tab ... and epn_20.atx if the
#           option EPN-strict has been asked)
#
# Created : 2016-01-05
# Updated : 2017-12-11 (by DM) : option strict modified (E, D or default)
#           2018-01-23 (by DM) : strictness (about antenna) modified for the default (EPOS level)
#           2018-10-22 (by DM) : message formats modified
#           2020-04-02 (by DM) : list of countries corrected
#           2023-01-11 (by DM) : epn_14.atx replaced by epn_20.atx
#           2024-07-26 (by DM) : - detects the site log version (v1.0 or v2.0)
#                                - checks the 'Country or Region' when 'site log v2.0' (in place of 'Country')
#                                - checks the 'Nine Character ID' when 'site log v2.0' (in place of 'Four Character ID')
#                                - checks if the 'Date Installed' (in section 1) is later than the 'Date Installed' of the first receiver and antenna
#-------------------------------------------------------------------------------

select(STDERR); $| = 1;         # flush output buffer (STDERR)
select(STDOUT); $| = 1;         # flush output buffer (STDOUT)

use Getopt::Long;
use Getopt::Std;
use Cwd;
use Time::Local;
use Time::localtime;
use File::Basename;
use File::Copy;
use File::Temp qw/ tempfile tempdir /;
use File::Spec;
use strict;
use warnings;
use Date::Calc qw(:all);
use DBI;


sub trim($)
 {
  my $string = shift;
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  return $string;
 }

sub usage()
{

 print STDERR << "EOF";
***************************************************************************
 usage: CheckStationLogs.pl [-h] -l StationLogsDirectory -r ReferencesDirectory [-c CurrentLogDirectory] [-s Network]

 -h                      : this (help) message
 -l StationLogsDirectory : directory with submitted station logs -> MANDATORY
 -r ReferencesDirectory  : directory with reference files (antenna.gra, rcvr_ant.tab) -> MANDATORY
 -c CurrentLogDirectory  : directory with current station logs -> OPTIONAL
                           (to be used only to check the name of "Previous site log")
 -s Network              : choice of level of strictness of meta-data verification -> OPTIONAL
                           EPN (E), EPN DENSIFICATION (D) or EPOS (default)

 example : CheckStationLogs.pl -l /home/user/logs -r /home/user/references -s E
***************************************************************************

EOF
}

sub check_stationlogdate
{
my $stationlogdate = $_[0]; #print('-' . $stationlogdate . "-\n");
my $tm = localtime;
my $year = $tm->year+1900;
my $error_stationlogdate = '';

if (
   ($stationlogdate !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z$/ )
   &&
   ($stationlogdate !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/ )
   )
    {
      $error_stationlogdate = 'missing (or incomplete) input. Use CCYY-MM-DD or CCYY-MM-DDThh:mmZ.';
    }
else
    {
      if (
         (substr($stationlogdate,0,4) < 1800 ) ||
         (substr($stationlogdate,0,4) > $year) ||
         !(check_date(substr($stationlogdate,0,4), substr($stationlogdate,5,2), substr($stationlogdate,8,2))) ||
	 (
           (length($stationlogdate) == 17) &&
           (
           (substr($stationlogdate,11,2) < '00') ||
           (substr($stationlogdate,11,2) > '23') ||
           (substr($stationlogdate,14,2) < '00') ||
           (substr($stationlogdate,14,2) > '59')
           )
         )
         )
          {
             $error_stationlogdate = 'senseless date.';
          }
    }

return $error_stationlogdate;
}



my %option;
GetOptions (\%option, 'h', 'l=s', 'r=s', 'c=s', 's=s');

my $line;
my $i;

my $tm = localtime;
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
my $sec = $tm->sec;
my $min = $tm->min;
my $hour = $tm->hour;
my $day = $tm->mday;
my $month = $tm->mon+1;
my $year = $tm->year+1900;

my $strict;

my @logfiles;
my $atxfile;
my $antfound;
my $atxfound;
my $hardwaretablesfile;
my $antennareferencepointsfile;
my $currentstationlogsdirectory;


my $tmp;
my @error_effective_dates;
my $error_date_installed;
my $error_date_removed;
my $previous_error_date_removed;

my $prepared_by;
my $date_prepared;
my $report_type;
my $previous_site_log;
my $modified_added_sections;

my $site_name;
my $four_character_id;
my $nine_character_id;
my $iers_domes_number;
my $cdp_number;
my $height_of_the_monument;
my $monument_inscription;
my $monument_foundation;
my $monument_description;
my $foundation_depth;
my $marker_description;
my $date_installed;
my $geologic_characteristic;
my $bedrock_type;
my $bedrock_condition;
my $fracture_spacing;
my $fault_zones_nearby;
my $distance_activity;
my $additional_information_section1;

my $city_or_town;
my $state_or_province;
my $country;
my $tectonic_plate;
my $x_coordinate;
my $y_coordinate;
my $z_coordinate;
my $latitude;
my $longitude;
my $elevation;
my $additional_information_section2;

my $number_receivers;
my %receiver;

my $number_antennae;
my %antenna;

my $number_localties;
my %localties;

my $number_frequencies;
my %frequencies;

my $number_instrumentation;
my %instrumentation;

my $number_humiditysensor;
my %humiditysensor;

my $number_pressuresensor;
my %pressuresensor;

my $number_temperaturesensor;
my %temperaturesensor;

my $number_watervaporradiometer;
my %watervaporradiometer;

my $number_otherinstrumentation;
my @otherinstrumentation;
my @otherinstrumentation_sectionnumber;

my $number_radiointerferences;
my %radiointerferences;

my $number_multipathsources;
my %multipathsources;

my $number_signalobstructions;
my %signalobstructions;

my $number_localepisodiceffects;
my %localepisodiceffects;

my $agency_section11;
my $preferredabbreviation_section11;
my $mailing_address_section11;
my $primarycontact_contactname_section11;
my $primarycontact_primarytelephone_section11;
my $primarycontact_secondarytelephone_section11;
my $primarycontact_fax_section11;
my $primarycontact_email_section11;
my $secondarycontact_contactname_section11;
my $secondarycontact_primarytelephone_section11;
my $secondarycontact_secondarytelephone_section11;
my $secondarycontact_fax_section11;
my $secondarycontact_email_section11;
my $additional_information_section11;

my $agency_section12;
my $preferredabbreviation_section12;
my $mailing_address_section12;
my $primarycontact_contactname_section12;
my $primarycontact_primarytelephone_section12;
my $primarycontact_secondarytelephone_section12;
my $primarycontact_fax_section12;
my $primarycontact_email_section12;
my $secondarycontact_contactname_section12;
my $secondarycontact_primarytelephone_section12;
my $secondarycontact_secondarytelephone_section12;
my $secondarycontact_fax_section12;
my $secondarycontact_email_section12;
my $additional_information_section12;

my $primary_data_center;
my $secondary_data_center;
my $url_for_more_information;
my $site_map;
my $site_diagram;
my $horizon_mask;
my $monument_description_MI;
my $site_pictures;
my $additional_information_section13;
my $antenna_graphics_with_dimensions;

#######################################################################
# CHECK FOR HELP OPTION
#######################################################################
if (defined($option{h}))
 {
  usage();
  exit;
 }
#######################################################################


#######################################################################
# CHECK FOR THE STRICT OPTION --> OPTIONAL
#######################################################################
if (defined($option{s}))
 {
   $strict = ($option{s});
 }
else
 {
   $strict = '';
 }
#######################################################################




print("\n" . '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' . "\n");

#######################################################################
# CHECK FOR STATION LOGS DIRECTORY --> MANDATORY
#######################################################################
if (defined($option{l}))
{
   my $stationlogsdirectory = ($option{l});


    if( -d $stationlogsdirectory )
     {
        if(substr($stationlogsdirectory,-1,1) ne '/') { $stationlogsdirectory = $stationlogsdirectory . '/'; }
	print("STATION LOGS DIRECTORY              : " . $stationlogsdirectory . " exists\n");
        @logfiles = glob($stationlogsdirectory . '*.log');
        #foreach (@logfiles) { print "$_\n"; }
     }
   else
     {
	print("STATION LOGS DIRECTORY              : " . $stationlogsdirectory . " does not exist\n");
        usage();
        exit;
     }
}
else
{
  usage();
  exit;
}
#######################################################################

#######################################################################
# CHECK FOR REFERENCE FILES --> MANDATORY
#######################################################################
if (defined($option{r}))
{
   my $referencefilesdirectory = ($option{r});
   if( -d $referencefilesdirectory )
     {
        if(substr($referencefilesdirectory,-1,1) ne '/') { $referencefilesdirectory = $referencefilesdirectory . '/'; }
        print("REFERENCE FILES DIRECTORY           : " . $referencefilesdirectory . " exists\n");
        $hardwaretablesfile = $referencefilesdirectory . 'rcvr_ant.tab';
        $antennareferencepointsfile = $referencefilesdirectory . 'antenna.gra';
        $atxfile = $referencefilesdirectory . 'epn_20.atx';


        if(-e $hardwaretablesfile)
          {
            print("HARDWARE TABLES FILE (rcvr-ant.tab) : " . $hardwaretablesfile . " exists\n");
          }
        else
          {
            print("HARDWARE TABLES FILE (rcvr-ant.tab) : " . $hardwaretablesfile . " does not exist\n");
            usage();
            exit;
          }

        if(-e $antennareferencepointsfile)
          {
            print("ARP FILE (antenna.gra)              : " . $antennareferencepointsfile . " exists\n");
          }
        else
          {
            print("ARP FILE (antenna.gra)              : " . $antennareferencepointsfile . " does not exist\n");
            usage();
            exit;
          }

        if(-e $atxfile)
          {
            print("ATX FILE (epn_20.atx)               : " . $atxfile . " exists\n");
          }
        else
          {
            print("ATX FILE (epn_20.atx)               : " . $atxfile . " does not exist\n");
            usage();
            exit;
          }


     }
   else
     {
        print("REFERENCE FILES DIRECTORY           : " . $referencefilesdirectory . " does not exist\n");
        usage();
        exit;
     }
}
else
{
  usage();
  exit;
}
#######################################################################





#######################################################################
# CHECK FOR CURRENT STATION LOGS DIRECTORY --> OPTIONAL
#######################################################################
if (defined($option{c}))
{
   $currentstationlogsdirectory = ($option{c});

    if( -d $currentstationlogsdirectory )
     {
        if(substr($currentstationlogsdirectory,-1,1) ne '/') { $currentstationlogsdirectory = $currentstationlogsdirectory . '/'; }
	print("CURRENT STATION LOGS DIRECTORY      : " . $currentstationlogsdirectory . " exists\n");
     }
   else
     {
	print("CURRENT STATION LOGS DIRECTORY              : " . $currentstationlogsdirectory . " does not exist\n");
        usage();
        exit;
     }
}
else
{
$currentstationlogsdirectory = '';
}
#######################################################################


print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' . "\n");




foreach (@logfiles)
 {
  my $numbererrors = 0;

  my $encounteredproblem = '';

  my $logfile = basename("$_");

  my $fourid = uc(substr($logfile,0,4));
  my $nineid = uc(substr($logfile,0,9));

=pod
  print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  print("File: " . $logfile . "\n");
  print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
=cut

  open (LogFile, "$_") || die "Cannot open $_";

  #######################################################################
  # READ SECTION 0.
  #######################################################################
  my $markername_firstline = '';
  my $log_version = '1.0';
  while ( ( $line !~ /^1.\s*Site\s*Identification\s*of\s*the\s*GNSS\s*Monument\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;

       my @test_firstline = split(/\s+/,$line); #print $test_firstline[1]  . "\n";
       if ( ($test_firstline[2] eq 'Site') && ($test_firstline[3] eq 'Information') && ($test_firstline[4] eq 'Form') ) { $markername_firstline = $test_firstline[1]; }

       if ( (defined($test_firstline[7])) && ($test_firstline[7] eq 'v2.0)') )  # "Site Information Form (site log v2.0)" or "Site Information Form (site log)"
        {
          $log_version = '2.0'; # print($log_version . "\n"); # print($test_firstline[7]); exit;
        }

       if (substr($line,0,32) =~ /\s*SitePrepared\s*by\s*\(full name\)\s*/i ) { $prepared_by = trim(substr($line,32,length($line)-33)); }

       if (substr($line,0,32) =~ /\s*Prepared\s*by\s*\(full name\)\s*/i ) { $prepared_by = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Date\s*Prepared\s*/i )               { $date_prepared = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Report\s*Type\s*/i )                 { $report_type = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Previous\s*Site\s*Log\s*/i )         { $previous_site_log = trim(substr($line,32,length($line)-33)); }

       if (substr($line,0,32) =~ /\s*Modified\/Added\s*Sections\s*/i )
              {
                  $modified_added_sections = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $modified_added_sections .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Sections 0 and 1 - no empty line between these two sections'; }

              }

     }

   $prepared_by =~s/ç/&ccedil;/g;
   $prepared_by =~s/Ã§/&ccedil;/g;
   $prepared_by =~s/ó/&oacute;/g;
   $prepared_by =~s/Ã³/&oacute;/g;

   $prepared_by =~s/é/&eacute;/g;
   $prepared_by =~s/Ã©/&eacute;/g;

   $prepared_by =~s/á/&aacute;/g;
   $prepared_by =~s/Ã¡/&aacute;/g;

   $prepared_by =~s/\'/&#39;/g;
   $prepared_by =~s/"/&#39;/g;

   $prepared_by =~s/ü/&uuml;/g;

   $prepared_by =~s/ñ/&ntilde;/g;

  print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  print("File: " . $logfile . "\n");
  print("Site Information Form Version: " . $log_version . "\n");
  print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");


   if ( (substr($markername_firstline,0,4) ne $fourid) && ($markername_firstline ne $nineid) && (length($markername_firstline) > 0) )
    {
      print('Header - "' . $markername_firstline . ' Site Information Form (site log)' . "\"\n");
      print('ERROR : wrong marker name. Use A4 or A9 (usage of RINEX 3 A9 site naming is recommended).' . "\n");
      $numbererrors++;
    }

   if ( ($markername_firstline eq $fourid) && (length($markername_firstline) == 4) )
    {
      print('Header - "' . $markername_firstline . ' Site Information Form (site log)' . "\"\n");
      print('WARNING : usage of RINEX 3 A9 site naming is recommended.' . "\n");
      $numbererrors++;
    }



   if (length(trim($prepared_by)) == 0)
    {
      print('Section 0 - "Prepared by (full name) : ' . "\"\n");
      print('ERROR : missing input. Use A48.' . "\n");
      $numbererrors++;
    }

   if ($date_prepared !~ /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/ )
    {
      print('Section 0 - "Date Prepared : ' . "\"\n");
      print('ERROR : missing or invalid format. Use CCYY-MM-DD format.' . "\n");
      $numbererrors++;
    }
   else
    {
      if ( !(check_date(substr($date_prepared,0,4), substr($date_prepared,5,2), substr($date_prepared,8,2))) )
          {
           print('Section 0 - "Date Prepared : ' . $date_prepared . "\"\n");
           print('ERROR : invalid date. Use CCYY-MM-DD format.' . "\n");
           $numbererrors++;
          }
    }

   if ( ($report_type ne 'NEW') && ($report_type ne 'UPDATE') )
    {
      print('Section 0 - "Report Type : ' . $report_type . "\"\n");
      print('ERROR : wrong input. Choose NEW or UPDATE.' . "\n");
      $numbererrors++;
    }


   if (
      ($previous_site_log !~ /^[a-z0-9]{4}_[0-9]{8}\.log$/ ) &&
      ($previous_site_log !~ /^[a-z0-9]{9}_[0-9]{8}\.log$/ ) &&
      ($report_type ne 'NEW')
      )
       {
         print('Section 0 - "Previous Site Log : ' . $previous_site_log . "\"\n");
         print('ERROR : invalid format. Use ssss_yyyymmdd.log or sssssssss_yyyymmdd.log.' . "\n");
         $numbererrors++;
       }
   else
       {
        if($currentstationlogsdirectory ne '')
         {
           if(my @filename = glob($currentstationlogsdirectory . lc($fourid) . "*.log"))
            {

             if (basename($filename[0]) ne $previous_site_log)
              {
               print('Section 0 - Previous Site Log : ' . $previous_site_log . "\n");
               print('ERROR : wrong input. ' . basename($filename[0]) . ' is expected.' . "\n");
               $numbererrors++;
              }

            }

         }
       }



  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 1 - title of that section not found.'; }





  #######################################################################
  # READ SECTION 1.
  #######################################################################
  while ( ($line !~ /^2.\s*Site\s*Location\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if (substr($line,0,32) =~ /\s*Site\s*Name\s*/i )                  { $site_name = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Four\s*Character\s*ID\s*/i )        { $four_character_id = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Nine\s*Character\s*ID\s*/i )        { $nine_character_id = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Monument\s*Inscription\s*/i )       { $monument_inscription = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*IERS\s*DOMES\s*Number\s*/i )        { $iers_domes_number = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*CDP\s*Number\s*/i )                 { $cdp_number = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Monument\s*Description\s*/i )       { $monument_description = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Height\s*of\s*the\s*Monument\s*/i ) { $height_of_the_monument = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Monument\s*Foundation\s*/i )        { $monument_foundation = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Foundation\s*Depth\s*/i )           { $foundation_depth = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Marker\s*Description\s*/i )         { $marker_description = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Date\s*Installed\s*/i )             { $date_installed = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Geologic\s*Characteristic\s*/i )    { $geologic_characteristic = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Bedrock\s*Type\s*/i )               { $bedrock_type = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Bedrock\s*Condition\s*/i )          { $bedrock_condition = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Fracture\s*Spacing\s*/i )           { $fracture_spacing = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Fault\s*zones\s*nearby\s*/i )       { $fault_zones_nearby = trim(substr($line,32,length($line)-33)); }

       if (substr($line,0,32) =~ /\s*Distance\/activity\s*/i )
              {
                  $distance_activity = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( ($line !~ /\s*Additional\s*Information\s*/i ) && (!eof(LogFile)) )
                    {
                      $distance_activity .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 1 - field "Additional Information" not found'; }
              }
       if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
              {
                  $additional_information_section1 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $additional_information_section1 .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Sections 1 and 2 - no empty line between these two sections'; }
              }
     }


   $site_name =~s/ü/&uuml;/g;
   $site_name =~s/\'/&#39;/g;
   $site_name =~s/"/&#39;/g;

   $site_name =~s/ç/&ccedil;/g;
   $site_name =~s/Ã§/&ccedil;/g;

   $site_name =~s/ó/&oacute;/g;
   $site_name =~s/Ã³/&oacute;/g;

   $site_name =~s/é/&eacute;/g;
   $site_name =~s/Ã©/&eacute;/g;

   $site_name =~s/õ/&otilde;/g;
   $site_name =~s/Ãµ/&otilde;/g;

   $site_name =~s/á/&aacute;/g;
   $site_name =~s/Ã¡/&aacute;/g;

   $site_name =~s/ö/&ouml;/g;
   $site_name =~s/Ã¶/&ouml;/g;

   $site_name =~s/ñ/&ntilde;/g;


   $monument_inscription =~s/\'/&#39;/g;
   $monument_inscription =~s/"/&#39;/g;
   $height_of_the_monument =~s/m$//;
   $height_of_the_monument =~s/\(m\)$//;
   $height_of_the_monument =~s/M$//;
   $height_of_the_monument =~s/meter$//;
   $height_of_the_monument =~ s/,/\./;
   $height_of_the_monument = trim($height_of_the_monument);
   $foundation_depth =~s/\(approximately\)$//;
   $foundation_depth = trim($foundation_depth);
   $foundation_depth =~s/^approx\.//;
   $foundation_depth =~s/^approximately//;
   $foundation_depth =~s/^approximatly//;
   $foundation_depth =~s/m$//;
   $foundation_depth =~s/\(m\)$//;
   $foundation_depth =~s/M$//;
   $foundation_depth =~ s/,/\./;
   $foundation_depth = trim($foundation_depth);
   $marker_description =~s/\'/&#39;/g;
   $marker_description =~s/"/&#39;/g;
   $bedrock_type = trim(uc($bedrock_type));
   $bedrock_condition = trim(uc($bedrock_condition));
   $fracture_spacing = lc($fracture_spacing);
   $distance_activity =~s/\'/&#39;/g;
   $distance_activity =~s/"/&#39;/g;
   $additional_information_section1 =~s/\'/&#39;/g;
   $additional_information_section1 =~s/"/&#39;/g;


   if ($height_of_the_monument eq '') { $height_of_the_monument = '(m)'; }
   if ($foundation_depth eq '') { $foundation_depth = '(m)'; }
   if ($geologic_characteristic eq '') { $geologic_characteristic = '(BEDROCK/CLAY/CONGLOMERATE/GRAVEL/SAND/etc)'; }
   if ($bedrock_type eq '') { $bedrock_type = '(IGNEOUS/METAMORPHIC/SEDIMENTARY)'; }
   if ($bedrock_condition eq '') { $bedrock_condition = '(FRESH/JOINTED/WEATHERED)'; }
   if ($fracture_spacing eq '(1-10 cm/11-50 cm/51-200 cm/over 200 cm)') { $fracture_spacing = '(0 cm/1-10 cm/11-50 cm/51-200 cm/over 200 cm)'; }
   if ($fracture_spacing eq '') { $fracture_spacing = '(0 cm/1-10 cm/11-50 cm/51-200 cm/over 200 cm)'; }
   if ($fault_zones_nearby eq '') { $fault_zones_nearby = '(YES/NO/Name of the zone)';}



   if (length(trim($site_name)) == 0)
    {
      print('Section 1 - "Site Name : ' . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   if ($log_version eq '1.0')
    {
     if ( ($four_character_id !~ /^[A-Z0-9]{4}$/ ) || (length(trim($four_character_id)) != 4) )
      {
       print('Section 1 - "Four Character ID : ' . $four_character_id . "\"\n");
       print('ERROR : invalid format. Use A4 (uppercase letters).' . "\n");
       $numbererrors++;
      }

     if ( (length(trim($four_character_id)) == 4) and (substr($markername_firstline,0,4) ne $four_character_id) )
      {
       print('Section 1 - "Four Character ID : ' . $four_character_id . "\"\n");
       print('ERROR : must correspond to first 4 characters of Site Identification in header (' . substr($markername_firstline,0,4) . ')' . "\n");
       $numbererrors++;
      }
    }

   if ($log_version eq '2.0')
    {
     if ( ($nine_character_id !~ /^[A-Z0-9]{9}$/ ) || (length(trim($nine_character_id)) != 9) )
      {
       print('Section 1 - "Nine Character ID : ' . $nine_character_id . "\"\n");
       print('ERROR : invalid format. Use A9 (uppercase letters).' . "\n");
       $numbererrors++;
      }

     if ( (length(trim($nine_character_id)) == 9) and (length(trim($markername_firstline)) == 9) and ($markername_firstline ne $nine_character_id) )
      {
       print('Section 1 - "Nine Character ID : ' . $nine_character_id . "\"\n");
       print('ERROR : must correspond to first 9 characters of Site Identification in header (' . substr($markername_firstline,0,9) . ')' . "\n");
       $numbererrors++;
      }
    }



   if ($strict eq 'E')
    {
     if (length(trim($iers_domes_number)) == 0)
      {
       print('Section 1 - "IERS DOMES Number : ' . "\"\n");
       print('ERROR : missing input (mandatory)' . "\n");
       $numbererrors++;
      }
     else
      {
       if ($iers_domes_number !~ /^[0-9]{5}[M,S]{1}[0-9]{3}$/ )
        {
         print('Section 1 - "IERS DOMES Number : ' . $iers_domes_number . "\"\n");
         print('ERROR : invalid format. Use A9.' . "\n");
         $numbererrors++;
        }
      }
    }

   if ($strict ne 'E')
    {
     if (length(trim($iers_domes_number)) == 0)
      {
       print('Section 1 - "IERS DOMES Number : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
     else
      {
       if ($iers_domes_number !~ /^[0-9]{5}[M,S]{1}[0-9]{3}$/ )
        {
         print('Section 1 - "IERS DOMES Number : ' . $iers_domes_number . "\"\n");
         print('ERROR : invalid format. Use A9.' . "\n");
         $numbererrors++;
        }
      }
    }

  if (
     (length(trim($cdp_number)) > 0) &&
     (trim($cdp_number) ne '(A4)') &&
     ($cdp_number !~ /^[A-Z0-9]{4}$/ )
     )
    {
      print('Section 1 - "CDP Number : ' . $cdp_number . "\"\n");
      print('ERROR : invalid format. Use A4 (uppercase letters).' . "\n");
      $numbererrors++;
    }

   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if (length(trim($monument_description)) == 0)
      {
       print('Section 1 - "Monument Description : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }




   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if ( (length(trim($height_of_the_monument)) == 0) || (trim($height_of_the_monument) eq '(m)') )
      {
       print('Section 1 - "Height of the Monument : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }

   if (
      ($height_of_the_monument !~ /^[0-9]{1,2}\.[0-9]{1,3}$/ )
      &&
      ($height_of_the_monument !~ /^[0-9]{1,2}$/ )
      &&
      (trim($height_of_the_monument) ne '(m)')
      )
       {
         print('Section 1 - "Height of the Monument : ' . $height_of_the_monument . "\"\n");
         print('ERROR : invalid format. Use F6.3 (or blank).' . "\n");
         $numbererrors++;
       }




   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if (length(trim($monument_foundation)) == 0)
      {
       print('Section 1 - "Monument Foundation : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }

   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if ( (length(trim($foundation_depth)) == 0) || (trim($foundation_depth) eq '(m)') )
      {
       print('Section 1 - "Foundation Depth : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }

   if (
      ($foundation_depth !~ /^[0-9]{1,2}\.[0-9]{1,2}$/ )
      &&
      ($foundation_depth !~ /^[0-9]{1,2}$/ )
      &&
      (trim($foundation_depth) ne '(m)')
      )
       {
         print('Section 1 - "Foundation Depth : ' . $foundation_depth . "\"\n");
         print('ERROR : invalid format. Use F5.2 (or blank).' . "\n");
         $numbererrors++;
       }



   $error_date_installed = check_stationlogdate($date_installed);
   if($error_date_installed ne '')
    {
      print('Section 1 - "Date Installed : ' . $date_installed . "\"\n");
      print($error_date_installed . "\n");
    }


   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if (length(trim($geologic_characteristic)) == 0)
      {
       print('Section 1 - "Geologic Characteristic : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }


   if (
      ($bedrock_type ne '') &&
      ($bedrock_type ne '(IGNEOUS/METAMORPHIC/SEDIMENTARY)') &&
      ($bedrock_type ne 'IGNEOUS') &&
      ($bedrock_type ne 'METAMORPHIC') &&
      ($bedrock_type ne 'SEDIMENTARY')
      )
    {
      print('Section 1 - "Bedrock Type : ' . $bedrock_type . "\"\n");
      print('ERROR : wrong input. Choose IGNEOUS or METAMORPHIC or SEDIMENTARY (or blank).' . "\n");
      $numbererrors++;
    }

   if (
      ($bedrock_type eq '') ||
      ($bedrock_type eq '(IGNEOUS/METAMORPHIC/SEDIMENTARY)')
      )
    {
      print('Section 1 - "Bedrock Type : ' . $bedrock_type . "\"\n");
      print('WARNING : missing input. Choose IGNEOUS or METAMORPHIC or SEDIMENTARY.' . "\n");
      $numbererrors++;
    }



   if (
      ($bedrock_condition ne '') &&
      ($bedrock_condition ne '(FRESH/JOINTED/WEATHERED)') &&
      ($bedrock_condition ne 'FRESH') &&
      ($bedrock_condition ne 'JOINTED') &&
      ($bedrock_condition ne 'WEATHERED')
      )
    {
      print('Section 1 - "Bedrock Condition : ' . $bedrock_condition . "\"\n");
      print('ERROR : wrong input. Choose FRESH or JOINTED or WEATHERED (or blank).' . "\n");
      $numbererrors++;
    }

   if (
      ($bedrock_condition eq '') ||
      ($bedrock_condition eq '(FRESH/JOINTED/WEATHERED)')
      )
    {
      print('Section 1 - "Bedrock Condition : ' . $bedrock_condition . "\"\n");
      print('WARNING : missing input. Choose FRESH or JOINTED or WEATHERED.' . "\n");
      $numbererrors++;
    }



   if (
      ($fracture_spacing ne '') &&
      ($fracture_spacing ne '(0 cm/1-10 cm/11-50 cm/51-200 cm/over 200 cm)') &&
      ($fracture_spacing ne '0 cm') &&
      ($fracture_spacing ne '1-10 cm') &&
      ($fracture_spacing ne '11-50 cm') &&
      ($fracture_spacing ne '51-200 cm') &&
      ($fracture_spacing ne 'over 200 cm')
      )
    {
      print('Section 1 - "Fracture Spacing : ' . $fracture_spacing . "\"\n");
      print('ERROR : wrong input. Choose "0 cm" or "1-10 cm" or "11-50 cm" or "51-200 cm" or "over 200 cm" (or blank).' . "\n");
      $numbererrors++;
    }

   if (
      ($fracture_spacing eq '') ||
      ($fracture_spacing eq '(0 cm/1-10 cm/11-50 cm/51-200 cm/over 200 cm)')
      )
    {
      print('Section 1 - "Fracture Spacing : ' . $fracture_spacing . "\"\n");
      print('WARNING : missing input. Choose "0 cm" or "1-10 cm" or "11-50 cm" or "51-200 cm" or "over 200 cm".' . "\n");
      $numbererrors++;
    }

   if ( ($strict ne 'E') and ($strict ne 'D') )
    {
     if (length(trim($fault_zones_nearby)) == 0)
      {
       print('Section 1 - "Fault zones nearby : ' . "\"\n");
       print('WARNING : missing input (recommended)' . "\n");
       $numbererrors++;
      }
    }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 2 - title of that section not found.'; }



  #######################################################################
  # READ SECTION 2.
  #######################################################################
  while ( ( $line !~ /^3.\s*GNSS\s*Receiver\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if (substr($line,0,32) =~ /\s*City\s*or\s*Town\s*/i )            { $city_or_town = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*State\s*or\s*Province\s*/i )       { $state_or_province = trim(substr($line,32,length($line)-33)); }
#       if (substr($line,0,32) =~ /\s*Country\s*/i )                     { $country = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Country\s*/i )
        {
          $country = trim(substr($line,32,length($line)-33));
          $line = <LogFile>;
          while ( ($line !~ /\s*Tectonic\s*Plate\s*/i ) && (!eof(LogFile)) )
           {
             $country .= ' ' . trim(substr($line,32,length($line)-33));
             $line = <LogFile>;
           }
          if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Tectonic Plate" not found in section No 2.'; }
        }

       if (substr($line,0,32) =~ /\s*Tectonic\s*Plate\s*/i )            { $tectonic_plate = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*X\s*coordinate\s*/i )              { $x_coordinate = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Y\s*coordinate\s*/i )              { $y_coordinate = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Z\s*coordinate\s*/i )              { $z_coordinate = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Latitude\s*\(N is \+\)\s*/i )      { $latitude = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Longitude\s*\(E is \+\)\s*/i )     { $longitude = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Elevation\s*\(m,ellips.\)\s*/i )   { $elevation = trim(substr($line,32,length($line)-33)); }

       if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
              {
                  $additional_information_section2 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $additional_information_section2 .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Sections 2 and 3 - no empty line between these two sections'; }

              }
     }

   $city_or_town =~s/\'/&#39;/g;
   $city_or_town =~s/"/&#39;/g;

   $city_or_town =~s/ç/&ccedil;/g;
   $city_or_town =~s/Ã§/&ccedil;/g;

   $city_or_town =~s/ó/&oacute;/g;

   $city_or_town =~s/é/&eacute;/g;
   $city_or_town =~s/Ã©/&eacute;/g;

   $city_or_town =~s/õ/&otilde;/g;
   $city_or_town =~s/Ãµ/&otilde;/g;

   $city_or_town =~s/ü/&uuml;/g;

   $city_or_town =~s/á/&aacute;/g;
   $city_or_town =~s/Ã¡/&aacute;/g;

   $city_or_town =~s/ö/&ouml;/g;
   $city_or_town =~s/Ã¶/&ouml;/g;

   $city_or_town =~s/ñ/&ntilde;/g;

   $state_or_province =~s/\'/&#39;/g;
   $state_or_province =~s/"/&#39;/g;
   $state_or_province =~s/ô/&ocirc;/g;
   $additional_information_section2 =~s/\'/&#39;/g;
   $additional_information_section2 =~s/"/&#39;/g;

   if (length(trim($city_or_town)) == 0)
    {
      print('Section 2 - "City or Town : ' . $city_or_town . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   if (length(trim($state_or_province)) == 0)
    {
      print('Section 2 - "State or Province : ' . $state_or_province . "\"\n");
      print('WARNING : missing input (recommended)' . "\n");
      $numbererrors++;
    }

   if ($log_version eq '1.0')
    {
     my @countries = ('Afghanistan','Aland Islands','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla',
                    'Antarctica','Antigua and Barbuda','Argentina','Armenia','Aruba','Australia',
                    'Austria','Azerbaijan','Bahamas (the)','Bahrain','Bangladesh','Barbados',
                    'Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia (Plurinational State of)',
                    'Bonaire, Sint Eustatius and Saba','Bosnia and Herzegovina','Botswana','Bouvet Island','Brazil',
                    'British Indian Ocean Territory (the)','Brunei Darussalam','Bulgaria','Burkina Faso',
                    'Burundi','Cabo Verde','Cambodia','Cameroon','Canada','Cayman Islands (the)',
                    'Central African Republic (the)','Chad','Chile','China','Christmas Island',
                    'Cocos (Keeling) Islands (the)','Colombia','Comoros (the)','Congo (the Democratic Republic of the)',
                    'Congo (the)','Cook Islands (the)','Costa Rica','Croatia','Cuba','Curaçao',
                    'Cyprus','Czechia','Côte d\'Ivoire','Denmark','Djibouti','Dominica','Dominican Republic (the)',
                    'Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Eswatini',
                    'Ethiopia','Falkland Islands (the) [Malvinas]','Faroe Islands (the)','Fiji','Finland',
                    'France','French Guiana','French Polynesia','French Southern Territories (the)','Gabon',
                    'Gambia (the)','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada',
                    'Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti',
                    'Heard Island and McDonald Islands','Holy See (the)','Honduras','Hong Kong','Hungary',
                    'Iceland','India','Indonesia','Iran (Islamic Republic of)','Iraq','Ireland','Isle of Man',
                    'Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati',
                    'Korea (the Democratic People\'s Republic of)','Korea (the Republic of)','Kuwait','Kyrgyzstan',
                    'Lao People\'s Democratic Republic (the)','Latvia','Lebanon','Lesotho',
                    'Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macao','Madagascar','Malawi',
                    'Malaysia','Maldives','Mali','Malta','Marshall Islands (the)','Martinique','Mauritania',
                    'Mauritius','Mayotte','Mexico','Micronesia (Federated States of)','Moldova (the Republic of)',
                    'Monaco','Mongolia','Montenegro','Montserrat','Morocco','Mozambique','Myanmar',
                    'Namibia','Nauru','Nepal','Netherlands (the)','New Caledonia','New Zealand','Nicaragua','Niger (the)',
                    'Nigeria','Niue','Norfolk Island','Northern Mariana Islands (the)','Norway',
                    'Oman','Pakistan', 'Palau','Palestine, State of','Panama','Papua New Guinea','Paraguay','Peru','Philippines (the)','Pitcairn',
                    'Poland','Portugal','Puerto Rico','Qatar',
                    'Republic of North Macedonia','Romania','Russian Federation (the)',
                    'Rwanda','Réunion','Saint Barthélemy','Saint Helena, Ascension and Tristan da Cunha','Saint Kitts and Nevis','Saint Lucia','Saint Martin (French part)',
                    'Saint Pierre and Miquelon','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe',
                    'Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Sint Maarten (Dutch part)',
                    'Slovakia','Slovenia','Solomon Islands','Somalia','South Africa','South Georgia and the South Sandwich Islands',
                    'South Sudan','Spain','Sri Lanka','Sudan (the)','Suriname','Svalbard and Jan Mayen','Sweden','Switzerland',

                    'Syrian Arab Republic','Taiwan (Province of China)','Tajikistan','Tanzania, United Republic of','Thailand','Timor-Leste',
                    'Togo','Tokelau','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Turks and Caicos Islands (the)',
                    'Tuvalu','Uganda','Ukraine','United Arab Emirates (the)','United Kingdom of Great Britain and Northern Ireland (the)',
                    'United States Minor Outlying Islands (the)','United States of America (the)','Uruguay','Uzbekistan','Vanuatu',
                    'Venezuela (Bolivarian Republic of)','Viet Nam','Virgin Islands (British)','Virgin Islands (U.S.)','Wallis and Futuna',
                    'Western Sahara','Yemen','Zambia','Zimbabwe');

     my $countryfound = 'false';
     foreach my $value (@countries) { if($country eq $value) { $countryfound = 'true'; } }
     if ($countryfound eq 'false')
      {
       print('Section 2 - "Country : ' . $country . "\"\n");
       print('ERROR : wrong or missing input (see http://unstats.un.org/unsd/methods/m49/m49alpha.htm).' . "\n");
       $numbererrors++;
      }
    }



   if ($log_version eq '2.0')
    {
     my @countryacronyms = ('AFG','ALA','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','AUS','AUT','AZE',
                            'BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BES','BIH','BWA','BVT','BRA','IOT','VGB','BRN','BGR','BFA','BDI',
                            'CPV','KHM','CMR','CAN','CYM','CAF','TCD','CHL','CHN','HKG','MAC','CXR','CCK','COL','COM','COG','COK','CRI','CIV','HRV','CUB','CUW','CYP','CZE',
                            'PRK','COD','DNK','DJI','DMA','DOM',
                            'ECU','EGY','SLV','GNQ','ERI','EST','SWZ','ETH',
                            'FLK','FRO','FJI','FIN','FRA','GUF','PYF','ATF',
                            'GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GGY','GIN','GNB','GUY',
                            'HTI','HMD','VAT','HND','HUN',
                            'ISL','IND','IDN','IRN','IRQ','IRL','IMN','ISR','ITA',
                            'JAM','JPN','JEY','JOR',
                            'KAZ','KEN','KIR','KWT','KGZ',
                            'LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX',
                            'MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MCO','MNG','MNE','MSR','MAR','MOZ','MMR',
                            'NAM','NRU','NPL','NLD','NCL','NZL','NIC','NER','NGA','NIU','NFK','MKD','MNP','NOR',
                            'OMN',
                            'PAK','PLW','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI',
                            'QAT',
                            'KOR','MDA','REU','ROU','RUS','RWA',
                            'BLM','SHN','KNA','LCA','MAF','SPM','VCT','WSM','SMR','STP','SAU','SEN','SRB','SYC','SLE','SGP','SXM','SVK','SVN','SLB','SOM','ZAF','SGS','SSD','ESP','LKA','PSE','SDN','SUR','SJM','SWE','CHE','SYR',
                            'TJK','THA','TLS','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV',
                            'UGA','UKR','ARE','GBR','TZA','UMI','USA','VIR','URY','UZB',
                            'VUT','VEN','VNM',
                            'WLF','ESH',
                            'YEM',
                            'ZMB','ZWE');
     my $countryfound = 'false';
     foreach my $value (@countryacronyms) { if($country eq $value) { $countryfound = 'true'; } }
     if ($countryfound eq 'false')
      {
       print('Section 2 - "Country : ' . $country . "\"\n");
       print('ERROR : wrong or missing input (see ISO-alpha3 code in http://unstats.un.org/unsd/methods/m49/m49alpha.htm).' . "\n");
       $numbererrors++;
      }

    }



   my @tectonic_plates = ('AFRICAN','ANTARTIC','ARABIAN','AUSTRALIAN','CARIBBEAN','COCOS','EURASIAN',
                          'INDIAN','JUAN DE FUCA','NAZCA','NORTH AMERICAN','PACIFIC','PHILIPPINE','SCOTIA','SOUTH AMERICAN');

   my $tectonicplatefound = 'false';
   my $tmp_tp = '';
   foreach my $value (@tectonic_plates)
    {
      if($tectonic_plate eq $value) { $tectonicplatefound = 'true'; }
      $tmp_tp .= $value . ', ';
    }
   if ($tectonicplatefound eq 'false')
    {
      print('Section 2 - "Tectonic Plate : ' . $tectonic_plate . "\"\n");
      print('ERROR : wrong or missing input. Choose between ' . substr($tmp_tp,0,-2) . "\n");
      $numbererrors++;
    }




   if (length(trim($x_coordinate)) == 0)
    {
      print('Section 2 - "X coordinate (m) : ' . $x_coordinate . "\"\n");
      print('ERROR : missing input. Use integer or float.' . "\n");
      $numbererrors++;
    }

  if (
      ($x_coordinate !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ )
      &&
      ($x_coordinate !~ /^[-]{0,1}[0-9]{1,}$/ )
      &&
      (trim($x_coordinate) ne '')
      )
    {
      print('Section 2 - "X coordinate (m) : ' . $x_coordinate . "\"\n");
      print('ERROR : invalid format. Use integer or float.' . "\n");
      $numbererrors++;
    }




   if (length(trim($y_coordinate)) == 0)
    {
      print('Section 2 - "Y coordinate (m) : ' . $y_coordinate . "\"\n");
      print('ERROR : missing input. Use integer or float.' . "\n");
      $numbererrors++;
    }

  if (
      ($y_coordinate !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ )
      &&
      ($y_coordinate !~ /^[-]{0,1}[0-9]{1,}$/ )
      &&
      (trim($y_coordinate) ne '')
      )
    {
      print('Section 2 - "Y coordinate (m) : ' . $y_coordinate . "\"\n");
      print('ERROR : invalid format. Use integer or float.' . "\n");
      $numbererrors++;
    }





   if (length(trim($z_coordinate)) == 0)
    {
      print('Section 2 - "Z coordinate (m) : ' . $z_coordinate . "\"\n");
      print('ERROR : missing input. Use integer or float.' . "\n");
    }

   if (
      ($z_coordinate !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ )
      &&
      ($z_coordinate !~ /^[-]{0,1}[0-9]{1,}$/ )
      &&
      (trim($z_coordinate) ne '')
      )
    {
      print('Section 2 - "Z coordinate (m) : ' . $z_coordinate . "\"\n");
      print('ERROR : invalid format. Use integer or float.' . "\n");
      $numbererrors++;
    }





   if (
      ($latitude !~ /^[+,-]{1}[0-9]{1}[0-9]{1}[0-5]{1}[0-9]{1}[0-5]{1}[0-9]{1}\.[0-9]{2}$/ ) ||
      (substr($latitude,1,2) gt '90' ) ||
      (
        (substr($latitude,1,2) eq '90') &&
        (substr($latitude,3,7) ne '0000.00')
      )
      )
    {
      print('Section 2 - "Latitude (N is +) : ' . $latitude . "\"\n");
      print('ERROR : invalid format. Use +/-DDMMSS.SS.' . "\n");
      $numbererrors++;
    }


   if (
      ($longitude !~ /^[+,-]{1}[0-1]{1}[0-9]{1}[0-9]{1}[0-5]{1}[0-9]{1}[0-5]{1}[0-9]{1}\.[0-9]{2}$/ ) ||
      (substr($longitude,1,3) gt '180' ) ||
      (
        (substr($longitude,1,3) eq '180') &&
        (substr($longitude,3,7) ne '0000.00')
      )
      )
    {
      print('Section 2 - "Longitude (E is +) : ' . $longitude . "\"\n");
      print('ERROR : invalid format. Use +/-DDDMMSS.SS.' . "\n");
      $numbererrors++;
    }


   if (length(trim($elevation)) == 0)
    {
      print('Section 2 - "Elevation (m,ellips.) : ' . $elevation . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }


   if (
      ($elevation !~ /^[-0-9]{0,1}[0-9]{1,4}\.[0-9]{1}$/ ) &&
      (length(trim($elevation)) > 0)
      )
    {
      print('Section 2 - "Elevation (m,ellips.) : ' . $elevation . "\"\n");
      print('ERROR : invalid format. Use F7.1.' . "\n");
      $numbererrors++;
    }



  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 3 - title of that section not found.'; }



  #######################################################################
  # READ SECTION 3.
  #######################################################################
  $number_receivers = 0;

  while ( ( $line !~ /^4.\s*GNSS\s*Antenna\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Receiver\s*Type\s*/i ) && ($line !~ /\s*3.x\s*/i ) )
          {
            $number_receivers++;
            $receiver{type}[$number_receivers] = uc(trim(substr($line,32,length($line)-33)));
            $receiver{sectionnumber}[$number_receivers] = trim(substr($line,2,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Satellite\s*System\s*/i )           { $receiver{satellite_system}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Serial\s*Number\s*:\s*/i )          { $receiver{serial_number}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Firmware\s*Version\s*/i )           { $receiver{firmware_version}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Elevation\s*Cutoff\s*Setting\s*/i ) { $receiver{elevation_cutoff_setting}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Date\s*Installed\s*:\s*/i )         { $receiver{date_installed}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Date\s*Removed\s*:\s*/i )           { $receiver{date_removed}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Temperature\s*Stabiliz\.\s*/i )     { $receiver{temperature_stabilization}[$number_receivers] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $receiver{additional_information}[$number_receivers] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $receiver{additional_information}[$number_receivers] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 3.' . $receiver{sectionnumber}[$number_receivers] . ' - no empty line after that subsection'; }

                 }

              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 3.' . $receiver{sectionnumber}[$number_receivers] . ' - no empty line after that subsection'; }

          }
     }

  if (
     ($receiver{date_installed}[1] lt $date_installed) &&
     ($receiver{date_installed}[1] ne '(CCYY-MM-DDThh:mmZ)') &&
     ($receiver{date_installed}[1] ne 'CCYY-MM-DDThh:mmZ') &&
     ($date_installed ne '(CCYY-MM-DDThh:mmZ)') &&
     ($date_installed ne 'CCYY-MM-DDThh:mmZ')
     )
   {
       print('Section 3.1 - "Date Installed : ' . $receiver{date_installed}[1] . "\"\n");
       print('ERROR : earlier than the installation date of the station (section 1 - ' . $date_installed . ').' . "\n");
       $numbererrors++;
   }

  $previous_error_date_removed = '';
  for($i=1;$i<=$number_receivers;$i++)
   {
     $receiver{additional_information}[$i] =~s/\'/&#39;/g;
     $receiver{additional_information}[$i] =~s/"/&#39;/g;

     $receiver{elevation_cutoff_setting}[$i] =~ s/deg$//;
     $receiver{elevation_cutoff_setting}[$i] = trim($receiver{elevation_cutoff_setting}[$i]);

     if (
         ($receiver{type}[$i] ne '(A20, from rcvr_ant.tab; see instructions)') or
         ($receiver{satellite_system}[$i] ne '(GPS/GLONASS/GPS+GLONASS)') or
         ($receiver{serial_number}[$i] ne '(A20, but note the first A5 is used in SINEX)') or
         ($receiver{firmware_version}[$i] ne '(A11)') or
         ($receiver{elevation_cutoff_setting}[$i] ne '(deg)') or
         ($receiver{date_installed}[$i] ne '(CCYY-MM-DDThh:mmZ)') or
         ($receiver{date_removed}[$i] ne '(CCYY-MM-DDThh:mmZ)') or
         ($receiver{temperature_stabilization}[$i] ne '(deg C) +/- (deg C)') or
         ($receiver{additional_information}[$i] ne '(multiple lines)')
         )
      {
      if ($receiver{date_installed}[$i] eq '(CCYY-MM-DDThh:mmZ)')
       {
         $receiver{date_installed}[$i] = 'CCYY-MM-DDThh:mmZ';
       }
      if ($receiver{date_removed}[$i] eq '(CCYY-MM-DDThh:mmZ)')
       {
         if ($i == $number_receivers)
          {
            print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Date Removed : ' . $receiver{date_removed}[$i] . "\"\n");
            print('ERROR : wrong format. Remove the brackets.' . "\n");
            $numbererrors++;
          }
         $receiver{date_removed}[$i] = 'CCYY-MM-DDThh:mmZ';
       }
      }

    # SECTION NUMBER
    if (($receiver{sectionnumber}[$i] - $i) > 0)
     {
      print('Section 3.' . $receiver{sectionnumber}[$i] . '' . "\n");
      print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
      $numbererrors++;
     }

    # RECEIVER TYPE
    if ( (length(trim($receiver{type}[$i])) == 0) || ($receiver{type}[$i] eq '(A20, from rcvr_ant.tab; see instructions)') )
     {
      print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Receiver Type : ' . $receiver{type}[$i] . "\"\n");
      print('ERROR : missing input. Choose in ' . $hardwaretablesfile . "\n");
      $numbererrors++;
     }

    my $recfound = 'false';
    open (RECTABFile, $hardwaretablesfile) || die "Cannot open $_";
    while (!eof(RECTABFile))
     {
       $line = <RECTABFile>;
       if (length($line) >= 22)
        {
          if ($receiver{type}[$i] eq trim(substr($line,2,20)))
           {
             $recfound = 'true';
           }
        }
     }
    close(RECTABFile);
    if ($recfound eq 'false')
     {
      print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Receiver Type : ' . $receiver{type}[$i] . "\"\n");
      print('ERROR : wrong input (not available in ' . $hardwaretablesfile . ').' . "\n");
      $numbererrors++;
     }


    # SATELLITE SYSTEM
    if (
       (length(trim($receiver{satellite_system}[$i])) == 0) ||
       (trim($receiver{satellite_system}[$i]) eq '(GPS/GLONASS/GPS+GLONASS)') ||
       (trim($receiver{satellite_system}[$i]) eq '(GPS+GLO+GAL+BDS+QZSS+IRNSS+SBAS)')
       )
     {
      print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Satellite System : ' . $receiver{satellite_system}[$i] . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
     }
    else
     {
      my $satellite_system_tmp = $receiver{satellite_system}[$i];
      $satellite_system_tmp =~ s/\+/ /g;
      $satellite_system_tmp =~ s/\// /g;
      $satellite_system_tmp =~ s/\(/ /g;
      $satellite_system_tmp =~ s/\)/ /g;

      my @satsys_list = split(/\s+/,$satellite_system_tmp);
      foreach my $value (@satsys_list)
       {
         if(index('GPS+GLO+GAL+BDS+QZSS+IRNSS+SBAS', $value) == -1)
          {
           print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Satellite System : ' . $receiver{satellite_system}[$i]  . "\"\n");
           print('ERROR : ' . $value . ' is incorrect. Use GPS and/or GLO and/or GAL and/or BDS and/or QZSS and/or IRNSS and/or SBAS separated by "+".' . "\n");
           $numbererrors++;
          }
       }
     }




    # RECEIVER SERIAL NUMBER
    if ($strict eq 'E')
    {
    if ( (length(trim($receiver{serial_number}[$i])) == 0) || ($receiver{serial_number}[$i] eq '(A20, but note the first A5 is used in SINEX)') )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Serial Number : ' . $receiver{serial_number}[$i] . "\"\n");
       print('ERROR : missing input. Use A20.' . "\n");
       $numbererrors++;
     }
    }

    if ( (length(trim($receiver{serial_number}[$i])) > 20) && ($receiver{serial_number}[$i] ne '(A20, but note the first A5 is used in SINEX)') )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Serial Number : ' . $receiver{serial_number}[$i] . "\"\n");
       print('ERROR : invalid format. Use A20.' . "\n");
       $numbererrors++;
     }

    # RECEIVER FIRMWARE VERSION
    if ( (length(trim($receiver{firmware_version}[$i])) == 0) || ($receiver{firmware_version}[$i] eq '(A11)') )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Firmware Version : ' . $receiver{firmware_version}[$i] . "\"\n");
       print('ERROR : missing input. Use A20.' . "\n");
       $numbererrors++;
     }

    if ( (length(trim($receiver{firmware_version}[$i])) > 20) && ($receiver{firmware_version}[$i] ne '(A11)') )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Firmware Version : ' . $receiver{firmware_version}[$i] . "\"\n");
       print('ERROR : invalid format. Use A20.' . "\n");
       $numbererrors++;
     }

    # ELEVATION CUTOFF SETTING
    if ($strict eq 'E')
     {
      if ( (length(trim($receiver{elevation_cutoff_setting}[$i])) == 0) || ($receiver{elevation_cutoff_setting}[$i] eq '(deg)') )
       {
        print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Elevation Cutoff Setting : ' . $receiver{elevation_cutoff_setting}[$i] . "\"\n");
        print('ERROR : missing input. Use A2.' . "\n");
        $numbererrors++;
       }
     }
    else
      {
      if ( (length(trim($receiver{elevation_cutoff_setting}[$i])) == 0) || ($receiver{elevation_cutoff_setting}[$i] eq '(deg)') )
       {
        print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Elevation Cutoff Setting : ' . $receiver{elevation_cutoff_setting}[$i] . "\"\n");
        print('WARNING : missing input (recommended). Use A2.' . "\n");
        $numbererrors++;
       }
     }


    if (
       ( ($receiver{elevation_cutoff_setting}[$i] !~ /^[0-9]{1,2}$/ ) || ($receiver{elevation_cutoff_setting}[$i] > 90) ) &&
       (length(trim($receiver{elevation_cutoff_setting}[$i])) > 0)
       )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Elevation Cutoff Setting : ' . $receiver{elevation_cutoff_setting}[$i] . "\"\n");
       print('ERROR : wrong format. Use A2 [0-90].' . "\n");
       $numbererrors++;
     }

    if (
       ( ($strict eq 'E') || ($strict eq 'D') ) &&
       ($receiver{elevation_cutoff_setting}[$i] =~ /^[0-9]{1,2}$/ ) &&
       (length(trim($receiver{elevation_cutoff_setting}[$i])) > 0) &&
       ($receiver{elevation_cutoff_setting}[$i] > 0)
       )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Elevation Cutoff Setting : ' . $receiver{elevation_cutoff_setting}[$i] . "\"\n");
       print('WARNING : EPN guidelines recommend a cut off of 0 deg.' . "\n");
       $numbererrors++;
     }


    # DATE INSTALLED
    $error_date_installed = check_stationlogdate($receiver{date_installed}[$i]);
    if($error_date_installed ne '')
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Date Installed : ' . $receiver{date_installed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_installed . "\n");
       $numbererrors++;
     }

    # DATE REMOVED
    if($i < $number_receivers)
    {
    $error_date_removed = check_stationlogdate($receiver{date_removed}[$i]);
    if($error_date_removed ne '')
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Date Removed : ' . $receiver{date_removed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_removed . "\n");
       $numbererrors++;
     }
    }

    if(
      ($i == $number_receivers) &&
      ($receiver{date_removed}[$i] ne "CCYY-MM-DDThh:mmZ") &&
      ($receiver{date_removed}[$i] ne "CCYY-MM-DD") &&
      ($receiver{date_removed}[$i] ne "(CCYY-MM-DDThh:mmZ)") &&
      ($receiver{date_removed}[$i] ne "(CCYY-MM-DDThh:mm") &&
      ($receiver{date_removed}[$i] ne "")
      )
    {
    $error_date_removed = check_stationlogdate($receiver{date_removed}[$i]);
    if($error_date_removed ne '')
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Date Removed : ' . $receiver{date_removed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_removed . "\n");
       $numbererrors++;
     }
    }

    # DATE INSTALLED and DATE REMOVED : chronology comparison
    if (
       ($error_date_installed eq "") &&
       ($error_date_removed eq "") &&
       ($receiver{date_installed}[$i] gt $receiver{date_removed}[$i] )
       )
     {
       if (!(
            (substr($receiver{date_installed}[$i],0,10) eq substr($receiver{date_removed}[$i],0,10) ) &&
            (length($receiver{date_removed}[$i]) == 10) &&
            (substr($receiver{date_installed}[$i],10,7) eq 'T00:00Z')
            )
          )
        {
          print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Date Installed / Date Removed' . "\"\n");
          print('ERROR : Date Removed (' . $receiver{date_removed}[$i] . ') precedes Date Installed (' . $receiver{date_installed}[$i] . ')' . "\n");
          $numbererrors++;
        }
     }


    # DATE INSTALLED (current installation) and DATE REMOVED (previous installation) : chronology comparison
    if (
       ($error_date_installed eq "") &&
       ($previous_error_date_removed eq "") &&
       ($receiver{date_installed}[$i] lt $receiver{date_removed}[($i-1)] )
       )
      {
       if (!(
            (substr($receiver{date_installed}[$i],0,10) eq substr($receiver{date_removed}[($i-1)],0,10) ) &&
            (length($receiver{date_installed}[$i]) == 10) &&
            (substr($receiver{date_removed}[($i-1)],10,7) eq 'T00:00Z')
            )
          )
        {
          print('Sections 3.' . ($receiver{sectionnumber}[$i]-1) . ' and 3.' . $receiver{sectionnumber}[$i] . ' - "Date Installed (subsection 3.' . $receiver{sectionnumber}[$i] . ') / Date Removed (subsection 3.' . ($receiver{sectionnumber}[$i]-1) . ')' . "\"\n");
          print('ERROR : Date Installed (' . $receiver{date_installed}[$i] . ') precedes Date Removed (' . $receiver{date_removed}[($i-1)] . ')' . "\n");
          $numbererrors++;
        }
      }


    $previous_error_date_removed = $error_date_removed;



    # TEMPERATURE STABILIZATION
    if (
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\.[0-9]{1}\s*\+\/\-$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\s*\+\/\-$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^\+\/\-\s*[0-9]{1,2}$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^\+\/\-\s*[0-9]{1,2}\.[0-9]{1}$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\.[0-9]{1}\s*\+\/\-\s*[0-9]{1,2}\.[0-9]{1}$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\s*\+\/\-\s*[0-9]{1,2}\.[0-9]{1}$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\.[0-9]{1}\s*\+\/\-\s*[0-9]{1,2}$/ ) &&
       ($receiver{temperature_stabilization}[$i] !~ /^[0-9]{1,3}\s*\+\/\-\s*[0-9]{1,2}$/ ) &&
       (trim($receiver{temperature_stabilization}[$i]) ne '(deg C) +/- (deg C)') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '[0-9]{1,3}\.[0-9]{1}\s*\+\/\-\s*(deg C)') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '[0-9]{1,3}\s*\+\/\-\s*(deg C)') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '(deg C)\s*\+\/\-\s*[0-9]{1,2}\.[0-9]{1}') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '(deg C)\s*\+\/\-\s*[0-9]{1,2}') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '+/-') &&
       (trim($receiver{temperature_stabilization}[$i]) ne '') &&
       (trim($receiver{temperature_stabilization}[$i]) ne 'none') &&
       (trim($receiver{temperature_stabilization}[$i]) ne 'none+/-none')
       )
     {
       print('Section 3.' . $receiver{sectionnumber}[$i] . ' - "Temperature Stabiliz. : ' . $receiver{temperature_stabilization}[$i] . "\"\n");
       print('ERROR : invalid format. Use F4.1 +/- F3.1 or type "none" (or blank).' . "\n");
       $numbererrors++;
     }



   }


  if ($number_receivers == 0)
   {
    print('Section 3 - "GNSS Receiver Information\"' . "\n");
    print('ERROR : missing section' . "\n");
    $numbererrors++;
   }



  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 4 - title of that section not found'; }



  #######################################################################
  # READ SECTION 4.
  #######################################################################
  $number_antennae = 0;

  while ( ( $line !~ /^5.\s*Surveyed\s*Local\s*Ties\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Antenna\s*Type\s*/i ) && ($line !~ /\s*4.x\s*/i ) )
          {
            $number_antennae++;
            $antenna{type}[$number_antennae] = uc(trim(substr($line,32,length($line)-33)));
            $antenna{sectionnumber}[$number_antennae] = trim(substr($line,2,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if ( (substr($line,0,32) =~ /\s*Serial\s*Number\s*:\s*/i ) && ($line !~ /\s*Radome\s*/i ) )              { $antenna{serial_number}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Antenna\s*Reference\s*Point\s*/i )      { $antenna{antenna_reference_point}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Marker->ARP\s*Up\s*/i )      { $antenna{arp_up_ecc}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Marker->ARP\s*North\s*Ecc\(m\)\s*/i )      { $antenna{arp_north_ecc}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Marker->ARP\s*East\s*Ecc\(m\)\s*/i )      { $antenna{arp_east_ecc}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Alignment\s*from\s*True\s*N\s*/i )      { $antenna{alignment_from_true_n}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if ( (substr($line,0,32) =~ /\s*Antenna\s*Radome\s*Type\s*/i ) && ( $line !~ /\s*Additional Information\s*/i ) && (substr($line,0,20) ne "                    ") )    { $antenna{antenna_radome_type}[$number_antennae] = uc(trim(substr($line,32,length($line)-33))); }
                 if (substr($line,0,32) =~ /\s*Radome\s*Serial\s*Number\s*/i )      { $antenna{radome_serial_number}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Antenna\s*Cable\s*Type\s*/i )      { $antenna{antenna_cable_type}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Antenna\s*Cable\s*Length\s*/i )      { $antenna{antenna_cable_length}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Date\s*Installed\s*:\s*/i )             { $antenna{date_installed}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Date\s*Removed\s*:\s*/i )               { $antenna{date_removed}[$number_antennae] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $antenna{additional_information}[$number_antennae] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $antenna{additional_information}[$number_antennae] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 4.' . $antenna{sectionnumber}[$number_antennae] . ' . - no empty line after that subsection'; }

                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 4.' . $antenna{sectionnumber}[$number_antennae] . ' . - no empty line after that subsection'; }
          }
     }

  if (
     ($antenna{date_installed}[1] lt $date_installed) &&
     ($antenna{date_installed}[1] ne '(CCYY-MM-DDThh:mmZ)') &&
     ($antenna{date_installed}[1] ne 'CCYY-MM-DDThh:mmZ') &&
     ($date_installed ne '(CCYY-MM-DDThh:mmZ)') &&
     ($date_installed ne 'CCYY-MM-DDThh:mmZ')
     )
   {
       print('Section 4.1 - "Date Installed : ' . $antenna{date_installed}[1] . "\"\n");
       print('ERROR : earlier than the installation date of the station (section 1 - ' . $date_installed . ').' . "\n");
       $numbererrors++;
   }


  $previous_error_date_removed = '';
  for($i=1;$i<=$number_antennae;$i++)
   {

      $antenna{antenna_reference_point}[$i] = trim($antenna{antenna_reference_point}[$i]);

      $antenna{alignment_from_true_n}[$i] =~ s/deg$//;
      $antenna{alignment_from_true_n}[$i] = trim($antenna{alignment_from_true_n}[$i]);
      $antenna{antenna_cable_length}[$i] =~ s/\(m\)$//;
      $antenna{antenna_cable_length}[$i] =~ s/m$//;
      $antenna{antenna_cable_length}[$i] =~ s/^~//;
      $antenna{antenna_cable_length}[$i] =~ s/^UNDEFINED//;
      $antenna{antenna_cable_length}[$i] = trim($antenna{antenna_cable_length}[$i]);
      $antenna{additional_information}[$i] =~ s/\'/&#39;/g;
      $antenna{additional_information}[$i] =~ s/"/&#39;/g;

      if (
          ($antenna{type}[$i] ne '(A20, from rcvr_ant.tab; see instructions)') or
          ($antenna{serial_number}[$i] ne '(A*, but note the first A5 is used in SINEX)') or
          ($antenna{antenna_reference_point}[$i] ne '(BPA/BCR/XXX from "antenna.gra"; see instr.)') or
          ($antenna{arp_up_ecc}[$i] ne '(F8.4)') or
          ($antenna{arp_north_ecc}[$i] ne '(F8.4)') or
          ($antenna{arp_east_ecc}[$i] ne '(F8.4)') or
          ($antenna{alignment_from_true_n}[$i] ne '(deg; + is clockwise/east)') or
          ($antenna{antenna_radome_type}[$i] ne '(A4 from rcvr_ant.tab; see instructions)') or
          ($antenna{radome_serial_number}[$i] ne '') or
          ($antenna{antenna_cable_type}[$i] ne '(vendor & type number)') or
          ($antenna{antenna_cable_length}[$i] ne '(m)') or
          ($antenna{date_installed}[$i] ne '(CCYY-MM-DDThh:mmZ)') or
          ($antenna{date_removed}[$i] ne '(CCYY-MM-DDThh:mmZ)') or
          ($antenna{additional_information}[$i] ne '(multiple lines)')
          )
      {
      if ($antenna{date_installed}[$i] eq '(CCYY-MM-DDThh:mmZ)') { $antenna{date_installed}[$i] = 'CCYY-MM-DDThh:mmZ'; }

      if ($antenna{date_removed}[$i] eq '(CCYY-MM-DDThh:mmZ)')
       {
         if ($i == $number_antennae)
          {
            print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Date Removed : ' . $antenna{date_removed}[$i] . "\"\n");
            print('ERROR : wrong format. Remove the brackets.' . "\n");
            $numbererrors++;
          }
         $antenna{date_removed}[$i] = 'CCYY-MM-DDThh:mmZ';
       }

      }

    # SECTION NUMBER
    if (($antenna{sectionnumber}[$i] - $i) > 0)
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . '' . "\n");
      print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
      $numbererrors++;
     }


    # ANTENNA TYPE
    my $error_antennatype = 'false';
    if ( (length(trim($antenna{type}[$i])) == 0) || ($antenna{type}[$i] eq '(A20, from rcvr_ant.tab; see instructions)') )
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . $antenna{type}[$i] . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
     }

    $antfound = 'false';
    open (RECTABFile, $hardwaretablesfile) || die "Cannot open $_";
    while (!eof(RECTABFile))
     {
       $line = <RECTABFile>;
       if (length($line) >= 22)
        {
          if (trim(substr($antenna{type}[$i],0,16)) eq trim(substr($line,2,20)))
           {
             $antfound = 'true';
           }
        }
     }
    close(RECTABFile);
    if ($antfound eq 'false')
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . $antenna{type}[$i] . "\"\n");
      print('ERROR : wrong input. The antenna type ' . trim(substr($antenna{type}[$i],0,16)) . ' is not available from ' . $hardwaretablesfile . "\n");
      $numbererrors++;
      $error_antennatype = 'true';
     }



    # ANTENNA RADOME TYPE
    my $error_radometype = 'false';
    if ( (length(trim(substr(sprintf("%-20s",$antenna{type}[$i]),16,4))) == 0) || ($antenna{type}[$i] eq '(A20, from rcvr_ant.tab; see instructions)') )
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . $antenna{type}[$i] . "\"\n");
      print('ERROR : missing radome type in columns 17-20.' . "\n");
      $numbererrors++;
      $error_radometype = 'true';
     }

    if ( (length(trim($antenna{antenna_radome_type}[$i])) == 0) || ($antenna{antenna_radome_type}[$i] eq '(A4 from rcvr_ant.tab; see instructions)') )
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Radome Type : ' . $antenna{antenna_radome_type}[$i] . "\"\n");
      print('ERROR : missing input' . "\n");
      $error_radometype = 'true';
     }

    if ( trim(substr(sprintf("%-20s",$antenna{type}[$i]),16,4)) ne trim($antenna{antenna_radome_type}[$i]) )
     {
      print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Radome Type : ' . $antenna{antenna_radome_type}[$i] . "\"\n");
      print('ERROR : not equal to the radome type in columns 17-20 of the field "Antenna Type".' . "\n");
      $numbererrors++;
      $error_radometype = 'true';
     }
    else
     {
       my $radomefound = 'false';
       open (RECTABFile, $hardwaretablesfile) || die "Cannot open $_";
       while ( (!eof(RECTABFile)) && (substr($line,0,24) ne '| Antenna Domes        |') ) { $line = <RECTABFile>; }

       if (substr($line,0,24) eq '| Antenna Domes        |')
        {
          while ( (!eof(RECTABFile)) && (substr($line,0,24) ne '| Previously valid     |') )
           {
             $line = <RECTABFile>;
             if (trim($antenna{antenna_radome_type}[$i]) eq trim(substr($line,18,4))) { $radomefound = 'true'; }
           }
        }
       close(RECTABFile);

       if ($strict ne 'E')
        {
          if (trim($antenna{antenna_radome_type}[$i]) eq 'UNKN') { $radomefound = 'true'; }
        }

       if ($radomefound eq 'false')
        {
         print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Radome Type : ' . $antenna{antenna_radome_type}[$i] . "\"\n");
         print('ERROR : wrong input. The antenna radome type ' . $antenna{antenna_radome_type}[$i] . ' is not available from ' . $hardwaretablesfile . "\n");
         $numbererrors++;
         $error_radometype = 'true';
        }
     }

    # ANTENNA REFERENCE POINT
    my $ARP_found = '';
    open (RECTABFile, $antennareferencepointsfile) || die "Cannot open $_";
    while ( (!eof(RECTABFile)) && ( $line !~ /Machine-readable/g ) ) { $line = <RECTABFile>; }

       if ( $line !~ /Machine-readable/g )
        {
          while (!eof(RECTABFile))
           {
             $line = <RECTABFile>;
             if (trim($line) ne '')
              {
                (my $antennareferencepointtable_antenna,my $antennareferencepointtable_ARP, my $antennareferencepointtable_NRP) = split(/\s+/,trim($line));
                if (trim(substr($antenna{type}[$i],0,16)) eq $antennareferencepointtable_antenna) { $ARP_found = $antennareferencepointtable_ARP; }
              }
           }
        }
    close(RECTABFile);


    if (
       (trim($antenna{antenna_reference_point}[$i]) eq '') ||
       (trim($antenna{antenna_reference_point}[$i]) eq '(BPA/BCR/XXX from "antenna.gra"; see instr.)')
       )
      {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Reference Point : ' . $antenna{antenna_reference_point}[$i] . "\"\n");
       print('ERROR : missing input' . "\n");
       $numbererrors++;
      }

    if (
       (trim($antenna{antenna_reference_point}[$i]) ne '') &&
       (trim($antenna{antenna_reference_point}[$i]) ne '(BPA/BCR/XXX from "antenna.gra"; see instr.)') &&
       (trim($antenna{antenna_reference_point}[$i]) ne $ARP_found)
       )
      {
        if ($ARP_found ne '')
         {
           print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Reference Point : ' . $antenna{antenna_reference_point}[$i] . "\"\n");
           print('ERROR : wrong input. Replace ' . $antenna{antenna_reference_point}[$i] . ' by ' . $ARP_found . ".\n");
           $numbererrors++;
         }
        else
         {
           print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Reference Point : ' . $antenna{antenna_reference_point}[$i] . "\"\n");
           print('ERROR : there is no ARP for the antenna type ' . trim(substr($antenna{type}[$i],0,16)) . ' in the reference file antenna.gra.' . "\n");
           $numbererrors++;
         }
      }

    # ANTENNA SERIAL NUMBER
    if ( ($strict eq 'E') || ($strict eq 'D') )
     {
       if ( (length(trim($antenna{serial_number}[$i])) == 0) || ($antenna{serial_number}[$i] eq '(A*, but note the first A5 is used in SINEX)') )
        {
         print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Serial Number : ' . $antenna{serial_number}[$i] . "\"\n");
         print('ERROR : missing input.' . "\n");
         $numbererrors++;
        }
     }

    if ( (length(trim($antenna{serial_number}[$i])) > 20) && ($antenna{serial_number}[$i] ne '(A*, but note the first A5 is used in SINEX)') )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Serial Number : ' . $antenna{serial_number}[$i] . "\"\n");
       print('ERROR : invalid format. Use A20.' . "\n");
       $numbererrors++;
     }

    #MARKER->ARP UP ECC.
    if (
       ($antenna{arp_up_ecc}[$i] !~ /^[-0-9]{0,1}[0-9]{0,2}\.[0-9]{1,4}$/ ) &&
       ($antenna{arp_up_ecc}[$i] ne '(F8.4)') &&
       ($antenna{arp_up_ecc}[$i] ne '')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP Up Ecc. : ' . $antenna{arp_up_ecc}[$i] . "\"\n");
       print('ERROR : invalid format. Use F8.4.' . "\n");
       $numbererrors++;
     }

    if (
       (trim($antenna{arp_up_ecc}[$i]) eq '') ||
       ($antenna{arp_up_ecc}[$i] eq '(F8.4)')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP Up Ecc. : ' . $antenna{arp_up_ecc}[$i] . "\"\n");
       print('ERROR : missing input.' . "\n");
       $numbererrors++;
     }


    #MARKER->ARP NORTH ECC.
    if (
       ($antenna{arp_north_ecc}[$i] !~ /^[-0-9]{0,1}[0-9]{0,2}\.[0-9]{1,4}$/ ) &&
       ($antenna{arp_north_ecc}[$i] ne '(F8.4)') &&
       ($antenna{arp_north_ecc}[$i] ne '')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP North Ecc. : ' . $antenna{arp_north_ecc}[$i] . "\"\n");
       print('ERROR : invalid format. Use F8.4.' . "\n");
       $numbererrors++;
     }

    if (
       (trim($antenna{arp_north_ecc}[$i]) eq '') ||
       ($antenna{arp_north_ecc}[$i] eq '(F8.4)')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP North Ecc. : ' . $antenna{arp_north_ecc}[$i] . "\"\n");
       print('ERROR : missing input.' . "\n");
       $numbererrors++;
     }



    #MARKER->ARP EAST ECC.
    if (
       ($antenna{arp_east_ecc}[$i] !~ /^[-0-9]{0,1}[0-9]{0,2}\.[0-9]{1,4}$/ ) &&
       ($antenna{arp_east_ecc}[$i] ne '(F8.4)') &&
       ($antenna{arp_east_ecc}[$i] ne '')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP East Ecc. : ' . $antenna{arp_east_ecc}[$i] . "\"\n");
       print('ERROR : invalid format. Use F8.4.' . "\n");
       $numbererrors++;
     }

    if (
       (trim($antenna{arp_east_ecc}[$i]) eq '') ||
       ($antenna{arp_east_ecc}[$i] eq '(F8.4)')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Marker->ARP East Ecc. : ' . $antenna{arp_east_ecc}[$i] . "\"\n");
       print('ERROR : missing input.' . "\n");
       $numbererrors++;
     }

    # ALIGNMENT FROM THE TRUE NORTH
    if (
       ( ($antenna{alignment_from_true_n}[$i] !~ /^[0-9]{1,3}$/ ) || ($antenna{alignment_from_true_n}[$i] > 360) ) &&
       ($antenna{alignment_from_true_n}[$i] ne '(deg; + is clockwise/east)') &&
       ($antenna{alignment_from_true_n}[$i] ne '')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Alignment from True N : ' . $antenna{alignment_from_true_n}[$i] . "\"\n");
       print('ERROR : invalid format. Use integer value between 0 and 360 (+ is clockwise/east).' . "\n");
       $numbererrors++;
     }

    if ($strict eq 'E')
    {
    if (
       (trim($antenna{alignment_from_true_n}[$i]) eq '') ||
       ($antenna{alignment_from_true_n}[$i] eq '(deg; + is clockwise/east)')
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Alignment from True N : ' . $antenna{alignment_from_true_n}[$i] . "\"\n");
       print('ERROR : missing input. Use integer value between 0 and 360 (+ is clockwise/east).' . "\n");
       $numbererrors++;
     }
    }

    # CALIBRATION VALUES
    if (
       ($error_antennatype eq 'false') &&
       ($error_radometype eq 'false')
       )
     {


       $antfound = 'false';
       $atxfound = 'false';
       my $antfound_withanotherradome = 'false';

       open (ATXFile, $atxfile) || die "Cannot open $_";

       while (!eof(ATXFile))
        {
        $line = <ATXFile>;




        if ($strict eq 'E')
        {
        if (substr($line,60,16) eq 'TYPE / SERIAL NO')
         {
           if (
              (substr($line,0,20) eq $antenna{type}[$i])
              &&
              (
               (trim(substr($line,20,40)) eq '') ||
               (trim(substr($line,20,40)) eq $antenna{serial_number}[$i])
              )
              )
             {
               $antfound = 'true';
               while (substr($line,60,4) ne 'DAZI') { $line = <ATXFile>; }
               if (trim(substr($line,0,10)) ne '0.0') { $atxfound = 'true'; }
             }

         }
        }




        if  ($strict ne 'E')
        {
        my $antenna_with_radome_none = substr($antenna{type}[$i],0,16) . 'NONE';

        if (substr($line,60,16) eq 'TYPE / SERIAL NO')
         {
           if (
              (
              (substr($line,0,20) eq $antenna{type}[$i]) ||
              (substr($line,0,20) eq $antenna_with_radome_none)
              )
              &&
              (
               (trim(substr($line,20,40)) eq '') ||
               (trim(substr($line,20,40)) eq $antenna{serial_number}[$i])
              )
              )
             {
               $antfound = 'true';
               # for the stations which are not EPN, the calibration could be something other than type mean or individual
               $atxfound = 'true';
             }

         }


        if (substr($line,60,16) eq 'TYPE / SERIAL NO')
         {
           if (
              (substr($line,0,16) eq substr($antenna{type}[$i],0,16) ) &&
              (substr($line,16,4) ne substr($antenna{type}[$i],16,4) ) &&
              (substr($line,16,4) ne 'NONE')
              )
             {
               $antfound_withanotherradome = 'true';
             }

         }
        }

        }
       close(ATXFile);


       if ( ($antfound eq 'false') && ($antfound_withanotherradome eq 'false') )
        {
         print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . trim($antenna{type}[$i]) . "\"\n");
         print('ERROR : antenna calibration values not found in ' . $atxfile . "\n");
         $numbererrors++;
        }

       if ( ($antfound eq 'false') && ($antfound_withanotherradome eq 'true') )
        {
         print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . trim($antenna{type}[$i]) . "\"\n");
         print('ERROR : antenna calibration values not found in ' . $atxfile . '. However calibrations values are available for the same antenna with another radome type.' . "\n");
        $numbererrors++;
        }

       if ( ($antfound eq 'true') && ($atxfound eq 'false') )
        {
         print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Type : ' . trim($antenna{type}[$i]) . "\"\n");
         print('ERROR : no type mean (or individual) calibration values available in ' . $atxfile . "\n");
         $numbererrors++;
        }

       #print($antfound . " " . $atxfound . "\n");

     }

    # RADOME SERIAL NUMBER
    if (length(trim($antenna{radome_serial_number}[$i])) == 0 )
     {
       #print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Radome Serial Number : ' . trim($antenna{radome_serial_number}[$i]) . "\"\n");
       #print('WARNING : missing input (recommended).' . "\n");
       #$numbererrors++;
     }

    # ANTENNA CABLE TYPE
    if ( (length(trim($antenna{antenna_cable_type}[$i])) == 0 ) || ($antenna{antenna_cable_type}[$i] eq '(vendor & type number)') )
     {
       #print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Cable Type : ' . trim($antenna{antenna_cable_type}[$i]) . "\"\n");
       #print('WARNING : missing input (recommended).' . "\n");
       #$numbererrors++;
     }

    # ANTENNA CABLE LENGTH
    if (length(trim($antenna{antenna_cable_length}[$i])) == 0)
     {
       #print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Cable Length : ' . trim($antenna{antenna_cable_length}[$i]) . "\"\n");
       #print('WARNING : missing input (recommended).' . "\n");
       #$numbererrors++;
     }

    if (
       ($antenna{antenna_cable_length}[$i] !~ /^[-0-9]{1,}\.[0-9]{1,}$/ ) &&
       ($antenna{antenna_cable_length}[$i] !~ /^[-0-9]{1,}$/ ) &&
       (length(trim($antenna{antenna_cable_length}[$i])) > 0)
       )
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Antenna Cable Length : ' . $antenna{antenna_cable_length}[$i] . "\"\n");
       print('ERROR : invalid format. Use integer or float.' . "\n");
       $numbererrors++;
     }



    # DATE INSTALLED
    $error_date_installed = check_stationlogdate($antenna{date_installed}[$i]);
    if($error_date_installed ne '')
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Date Installed : ' . $antenna{date_installed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_installed . "\n");
       $numbererrors++;
     }

    # DATE REMOVED
    if($i < $number_antennae)
    {
    $error_date_removed = check_stationlogdate($antenna{date_removed}[$i]);
    if($error_date_removed ne '')
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Date Removed : ' . $antenna{date_removed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_removed . "\n");
       $numbererrors++;
     }
    }

    if(
      ($i == $number_antennae) &&
      ($antenna{date_removed}[$i] ne "CCYY-MM-DDThh:mmZ") &&
      ($antenna{date_removed}[$i] ne "CCYY-MM-DD") &&
      ($antenna{date_removed}[$i] ne "(CCYY-MM-DDThh:mmZ)") &&
      ($antenna{date_removed}[$i] ne "(CCYY-MM-DDThh:mm") &&
      ($antenna{date_removed}[$i] ne "")
      )
    {
    $error_date_removed = check_stationlogdate($antenna{date_removed}[$i]);
    if($error_date_removed ne '')
     {
       print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Date Removed : ' . $antenna{date_removed}[$i] . "\"\n");
       print('ERROR : ' . $error_date_removed . "\n");
       $numbererrors++;
     }
    }


    # DATE INSTALLED and DATE REMOVED : chronology comparison
    if (
       ($error_date_installed eq "") &&
       ($error_date_removed eq "") &&
       ($antenna{date_installed}[$i] gt $antenna{date_removed}[$i] )
       )
     {
       if (!(
            (substr($antenna{date_installed}[$i],0,10) eq substr($antenna{date_removed}[$i],0,10) ) &&
            (length($antenna{date_removed}[$i]) == 10) &&
            (substr($antenna{date_installed}[$i],10,7) eq 'T00:00Z')
            )
          )
        {
          print('Section 4.' . $antenna{sectionnumber}[$i] . ' - "Date Installed / Date Removed' . "\"\n");
          print('ERROR : Date Removed (' . $antenna{date_removed}[$i] . ') precedes Date Installed (' . $antenna{date_installed}[$i] . ')' . "\n");
          $numbererrors++;
        }
     }


    # DATE INSTALLED (current installation) and DATE REMOVED (previous installation) : chronology comparison
    if (
       ($error_date_installed eq "") &&
       ($previous_error_date_removed eq "") &&
       ($antenna{date_installed}[$i] lt $antenna{date_removed}[($i-1)] )
       )
      {
       if (!(
            (substr($antenna{date_installed}[$i],0,10) eq substr($antenna{date_removed}[($i-1)],0,10) ) &&
            (length($antenna{date_installed}[$i]) == 10) &&
            (substr($antenna{date_removed}[($i-1)],10,7) eq 'T00:00Z')
            )
          )
        {
          print('Sections 4.' . $antenna{sectionnumber}[($i-1)] . ' and 4.' . $antenna{sectionnumber}[$i] . ' - "Date Installed (subsection 4.' . $antenna{sectionnumber}[$i] . ') / Date Removed (subsection 4.' . $antenna{sectionnumber}[($i-1)] . ')' . "\"\n");
          print('ERROR : Date Installed (' . $antenna{date_installed}[$i] . ') precedes Date Removed (' . $antenna{date_removed}[($i-1)] . ')' . "\n");
          $numbererrors++;
        }
      }


    $previous_error_date_removed = $error_date_removed;



   }

  if ($number_antennae == 0)
   {
     print('Section 4 - "GNSS Antenna Information\"'  . "\n");
     print('ERROR : missing section' . "\n");
     $numbererrors++;
   }



  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 5 - title of that section not found.'; }


  #######################################################################
  # READ SECTION 5.
  #######################################################################
  $number_localties = 0;

  while ( ( $line !~ /^6.\s*Frequency\s*Standard\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Tied\s*Marker\s*Name\s*/i ) && ($line !~ /\s*5.x\s*/i ) )
          {
            $number_localties++;
            $localties{tied_marker_name}[$number_localties] = trim(substr($line,32,length($line)-33));
            $localties{sectionnumber}[$number_localties] = trim(substr($line,2,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Tied\s*Marker\s*Usage\s*/i )          { $localties{tied_marker_usage}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Tied\s*Marker\s*CDP\s*Number\s*/i )   { $localties{tied_marker_cdp_number}[$number_localties] = trim(substr($line,32,4)); }
                 if (substr($line,0,32) =~ /\s*Tied\s*Marker\s*DOMES\s*Number\s*/i ) { $localties{tied_marker_domes_number}[$number_localties] = trim(substr($line,32,9)); }
                 if (substr($line,0,32) =~ /\s*dx\s*\(m\)\s*/i )                     { $localties{dx}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*dy\s*\(m\)\s*/i )                     { $localties{dy}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*dz\s*\(m\)\s*/i )                     { $localties{dz}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Accuracy\s*\(mm\)\s*/i )              { $localties{accuracy}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Survey\s*method\s*/i )                { $localties{survey_method}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Date\s*Measured\s*/i )                { $localties{date_measured}[$number_localties] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $localties{additional_information}[$number_localties] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $localties{additional_information}[$number_localties] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 5.' . $localties{sectionnumber}[$number_localties] . ' - no empty line after that subsection'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 5.' . $localties{sectionnumber}[$number_localties] . ' - no empty line after that subsection'; }
          }
     }

  for($i=1;$i<=$number_localties;$i++)
   {
      $localties{tied_marker_name}[$i] =~ s/\'/&#39;/g;
      $localties{tied_marker_name}[$i] =~ s/"/&#39;/g;
      $localties{dx}[$i] =~ s/^\+//;
      $localties{dy}[$i] =~ s/^\+//;
      $localties{dz}[$i] =~ s/^\+//;
      $localties{dx}[$i] =~ s/m$//;
      $localties{dy}[$i] =~ s/m$//;
      $localties{dz}[$i] =~ s/m$//;
      $localties{dx}[$i] =~ s/,/\./;
      $localties{dy}[$i] =~ s/,/\./;
      $localties{dz}[$i] =~ s/,/\./;
      $localties{accuracy}[$i] =~ s/^\+\/\-//;
      $localties{accuracy}[$i] =~ s/mm$//;
      $localties{accuracy}[$i] =~ s/\(mm\)$//;
      $localties{additional_information}[$i] =~ s/\'/&#39;/g;
      $localties{additional_information}[$i] =~ s/"/&#39;/g;


      # SECTION NUMBER
      if (($localties{sectionnumber}[$i] - $i) > 0)
       {
        print('Section 5.' . $localties{sectionnumber}[$i] . '' . "\n");
        print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
        $numbererrors++;
       }


      # TIED MARKER NAME
      if (length(trim($localties{tied_marker_name}[$i])) == 0)
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Tied Marker Name : ' . $localties{tied_marker_name}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
       }

      # TIED MARKER USAGE
      if ( (length(trim($localties{tied_marker_usage}[$i])) == 0) || (trim($localties{tied_marker_usage}[$i]) eq '(SLR/VLBI/LOCAL CONTROL/FOOTPRINT/etc)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Tied Marker Usage : ' . $localties{tied_marker_usage}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }

      # TIED MARKER CDP NUMBER
      if (
          (length(trim($localties{tied_marker_cdp_number}[$i])) > 0) &&
          (length(trim($localties{tied_marker_cdp_number}[$i])) != 4) &&
          (trim($localties{tied_marker_cdp_number}[$i]) ne '(A4)')
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Tied Marker CDP Number : ' . $localties{tied_marker_cdp_number}[$i] . "\"\n");
         print('ERROR : invalid format. Use A4 (or blank)' . "\n");
         $numbererrors++;
       }

      # TIED MARKER DOMES NUMBER
      if (
          (length(trim($localties{tied_marker_domes_number}[$i])) > 0) &&
          (length(trim($localties{tied_marker_domes_number}[$i])) != 9) &&
          (trim($localties{tied_marker_domes_number}[$i]) ne '(A9)')
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Tied Marker DOMES Number : ' . $localties{tied_marker_domes_number}[$i] . "\"\n");
         print('ERROR : invalid format. Use A9 (or blank)' . "\n");
         $numbererrors++;
       }


      # Differential Components from GNSS Marker to the tied monument (ITRS) - dx (m)
      if ( (trim($localties{dx}[$i]) eq '') || (trim($localties{dx}[$i]) eq '(m)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dx (m) : ' . $localties{dx}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }

      if (
          (trim($localties{dx}[$i]) ne '') &&
          (trim($localties{dx}[$i]) ne '(m)') &&
          (trim($localties{dx}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
          (trim($localties{dx}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}$/ )
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dx (m) : ' . $localties{dx}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (or blank)' . "\n");
         $numbererrors++;
       }


      # Differential Components from GNSS Marker to the tied monument (ITRS) - dy (m)
      if ( (trim($localties{dy}[$i]) eq '') || (trim($localties{dy}[$i]) eq '(m)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dy (m) : ' . $localties{dy}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }

      if (
          (trim($localties{dy}[$i]) ne '') &&
          (trim($localties{dy}[$i]) ne '(m)') &&
          (trim($localties{dy}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
          (trim($localties{dy}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}$/ )
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dy (m) : ' . $localties{dy}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (or blank)' . "\n");
         $numbererrors++;
       }

      # Differential Components from GNSS Marker to the tied monument (ITRS) - dz (m)
      if ( (trim($localties{dz}[$i]) eq '') || (trim($localties{dz}[$i]) eq '(m)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dz (m) : ' . $localties{dz}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }

      if (
          (trim($localties{dz}[$i]) ne '') &&
          (trim($localties{dz}[$i]) ne '(m)') &&
          (trim($localties{dz}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
          (trim($localties{dz}[$i]) !~ /^[-0-9]{0,1}[0-9]{1,}$/ )
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Differential Components from GNSS Marker to the tied monument (ITRS) - dz (m) : ' . $localties{dz}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (or blank)' . "\n");
         $numbererrors++;
       }

      # ACCURACY
      if ( (trim($localties{accuracy}[$i]) eq '') || (trim($localties{accuracy}[$i]) eq '(mm)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Accuracy (mm) : ' . $localties{accuracy}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }


      if (
          (trim($localties{accuracy}[$i]) !~ /^[0-9]{1,}\.[0-9]{1,}$/ ) &&
          (trim($localties{accuracy}[$i]) !~ /^[0-9]{1,}$/ ) &&
          (trim($localties{accuracy}[$i]) !~ /^<\s{0,}[0-9]{1,}\.[0-9]{1,}$/ ) &&
          (trim($localties{accuracy}[$i]) !~ /^<\s{0,}[0-9]{1,}$/ ) &&
          (length(trim($localties{accuracy}[$i])) > 0) &&
          (trim($localties{accuracy}[$i]) ne '(mm)')
         )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Accuracy (mm) : ' . $localties{accuracy}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (may be preceded by "<" ) ... or blank' . "\n");
         $numbererrors++;
       }

      # SURVEY METHOD
      if ( (length(trim($localties{survey_method}[$i])) == 0) || (trim($localties{survey_method}[$i]) eq '(GPS CAMPAIGN/TRILATERATION/TRIANGULATION/etc)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Survey method : ' . $localties{survey_method}[$i] . "\"\n");
         if ($strict eq 'E') { print('ERROR : missing input' . "\n"); }
         if ($strict ne 'E') { print('WARNING : missing input (recommended)' . "\n"); }
         $numbererrors++;
       }

      # DATE MEASURED
      if ( (trim($localties{date_measured}[$i]) eq '') || (trim($localties{date_measured}[$i]) eq '(CCYY-MM-DDThh:mmZ)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Date Measured : ' . $localties{date_measured}[$i] . "\"\n");
         print('WARNING : missing input (recommended)' . "\n");
         $numbererrors++;
       }

      my $error_date_measured = check_stationlogdate($localties{date_measured}[$i]);
      if ( ($error_date_measured ne '') && (trim($localties{date_measured}[$i]) ne '(CCYY-MM-DDThh:mmZ)') )
       {
         print('Section 5.' . $localties{sectionnumber}[$i] . ' - "Date Measured : ' . $localties{date_measured}[$i] . "\"\n");
         print('ERROR : ' . $error_date_measured . "\n");
         $numbererrors++;
       }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 6 - title of that section not found.'; }



  #######################################################################
  # READ SECTION 6.
  #######################################################################
  $number_frequencies = 0;

  while ( ( $line !~ /^7.\s*Collocation\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Standard\s*Type\s*/i ) && ($line !~ /\s*6.x\s*/i ) )
          {
            $number_frequencies++;
            $frequencies{standard_type}[$number_frequencies] = trim(substr($line,32,length($line)-33));
            $frequencies{sectionnumber}[$number_frequencies] = trim(substr($line,2,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Input\s*Frequency\s*/i )   { $frequencies{input_frequency}[$number_frequencies] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )   { $frequencies{effective_dates}[$number_frequencies] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $frequencies{notes}[$number_frequencies] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $frequencies{notes}[$number_frequencies] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 6.' . $frequencies{sectionnumber}[$number_frequencies] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 6.' . $frequencies{sectionnumber}[$number_frequencies] . '.'; }
          }
     }

  for($i=1;$i<=$number_frequencies;$i++)
   {

       $frequencies{input_frequency}[$i] =~s/MHz$//;
       $frequencies{input_frequency}[$i] = trim($frequencies{input_frequency}[$i]);
       $frequencies{notes}[$i] =~s/\'/&#39;/g;
       $frequencies{notes}[$i] =~s/"/&#39;/g;

       # SECTION NUMBER
       if (($frequencies{sectionnumber}[$i] - $i) > 0)
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . '' . "\n");
         print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
         $numbererrors++;
        }


       # STANDARD TYPE
       if (
          (trim($frequencies{standard_type}[$i]) eq '' ) ||
          (trim($frequencies{standard_type}[$i]) eq '(INTERNAL or EXTERNAL H-MASER/CESIUM/etc)' )
          )
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Standard Type : ' . $frequencies{standard_type}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
        }

       my $internal_frequency;
       if (trim($frequencies{standard_type}[$i]) eq 'INTERNAL') { $internal_frequency = 'true'; }
       else  { $internal_frequency = 'false'; }

       if (
          (length(trim($frequencies{standard_type}[$i])) <= 9 ) &&
          (length(trim($frequencies{standard_type}[$i])) > 0 ) &&
          (trim($frequencies{standard_type}[$i]) ne 'INTERNAL')
          )
         {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Standard Type : ' . $frequencies{standard_type}[$i] . "\"\n");
         print('ERROR : invalid format. Use INTERNAL or EXTERNAL H-MASER/CESIUM/etc' . "\n");
         $numbererrors++;
         }

       my $external_frequency = 'false';
       if (length(trim($frequencies{standard_type}[$i])) > 9 )
         {
          if (substr(trim($frequencies{standard_type}[$i]),0,9) ne 'EXTERNAL ')
           {
             print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Standard Type : ' . $frequencies{standard_type}[$i] . "\"\n");
             print('ERROR : invalid format. Use INTERNAL or EXTERNAL H-MASER/CESIUM/etc' . "\n");
             $numbererrors++;
           }
          else
           {
             $external_frequency = 'true';
           }
         }


       # INPUT FREQUENCY
       if (
           ( $external_frequency eq 'true') &&
           ( ( length($frequencies{input_frequency}[$i]) == 0) or ($frequencies{input_frequency}[$i] eq '(if external)') )
          )
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Input Frequency : ' . $frequencies{input_frequency}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
        }

       if (
           ($internal_frequency eq 'true') &&
           (length($frequencies{input_frequency}[$i]) > 0) &&
           ($frequencies{input_frequency}[$i] ne '(if external)')
          )
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Input Frequency : ' . $frequencies{input_frequency}[$i] . "\"\n");
         print('ERROR : input frequency not allowed for INTERNAL frequency' . "\n");
         $numbererrors++;
        }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES (not for the LAST subsection)
       if (
          (trim($frequencies{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_frequencies)
          )
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
         $error_effective_dates[$i] = 'true';
         $numbererrors++;
        }

       if (
          (trim($frequencies{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_frequencies)
          )
        {
         if (
            (substr($frequencies{effective_dates}[$i],0,4) < 1980 ) ||
            (substr($frequencies{effective_dates}[$i],0,4) > $year)
            )
           {
            print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($frequencies{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
            $error_effective_dates[$i] = 'true';
            $numbererrors++;
           }

         if (
            (substr($frequencies{effective_dates}[$i],11,4) < 1980 ) ||
            (substr($frequencies{effective_dates}[$i],11,4) > $year)
            )
           {
            print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($frequencies{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
            $error_effective_dates[$i] = 'true';
            $numbererrors++;
           }

         $error_effective_dates[$i] = check_stationlogdate(substr($frequencies{effective_dates}[$i],0,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
            print('ERROR : start date -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
            $numbererrors++;
          }

         $error_effective_dates[$i] = check_stationlogdate(substr($frequencies{effective_dates}[$i],11,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
            print('ERROR : end date -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
            $numbererrors++;
          }

       }

       # EFFECTIVE DATES (ONLY for the LAST subsection)
       if (
          (trim($frequencies{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_frequencies)
          )
        {
         print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
         print('ERROR : fill only the start date using the format CCYY-MM-DD/CCYY-MM-DD' . "\n");
         $error_effective_dates[$i] = 'true';
         $numbererrors++;
        }

       if (
          (trim($frequencies{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_frequencies)
          )
        {
          if (
             (substr($frequencies{effective_dates}[$i],0,4) < 1980 ) ||
             (substr($frequencies{effective_dates}[$i],0,4) > $year)
             )
            {
             print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($frequencies{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD' . "\n");
             $error_effective_dates[$i] = 'true';
             $numbererrors++;
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($frequencies{effective_dates}[$i],0,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($frequencies{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . "\n");
             $numbererrors++;
           }
       }

       # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
       if (
          ($error_effective_dates[$i] eq '') &&
          ( substr($frequencies{effective_dates}[$i],0,10) gt substr($frequencies{effective_dates}[$i],11,11) )
          )
         {
           print('Section 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates : ' . $frequencies{effective_dates}[$i] . "\"\n");
           print('ERROR : the "Date Removed" precede the "Date Installed"' . "\n");
           $numbererrors++;
         }

       # EFFECTIVE DATES (chronology comparison between Date Installed and ... Date Removed of the previous installation)
       if (
          ($error_effective_dates[$i] eq '') &&
          ($error_effective_dates[($i-1)] eq '') &&
          ( substr($frequencies{effective_dates}[$i],0,10) lt substr($frequencies{effective_dates}[($i-1)],11,11) )
          )
       {
         print('Sections 6.' . $frequencies{sectionnumber}[($i-1)] . ' and 6.' . $frequencies{sectionnumber}[$i] . ' - "Effective Dates - start"  (subsection 6.' . $frequencies{sectionnumber}[$i] . ') / "Effective Dates - end" (subsection 6.' . $frequencies{sectionnumber}[($i-1)] . ')' . "\n");
         print('ERROR : ' . substr($frequencies{effective_dates}[$i],0,10) . ' precedes ' . substr($frequencies{effective_dates}[($i-1)],11,11) . "\n");
         $numbererrors++;
       }

   }

#  if ( ($strict eq 'E') || ($strict eq 'D') )
  if ($strict eq 'E')
  {
  if ($number_frequencies == 0)
   {
      print('Section 6 - "Frequency Standard : ' . "\"\n");
      print('ERROR : missing section' . "\n");
      $numbererrors++;
   }
  }


  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 7 not found.'; }



  #######################################################################
  # READ SECTION 7.
  #######################################################################
  $number_instrumentation = 0;

  while ( ( $line !~ /^8.\s*Meteorological\s*Instrumentation\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Instrumentation\s*Type\s*/i ) && ($line !~ /\s*7.x\s*/i ) )
          {
            $number_instrumentation++;
            $instrumentation{instrumentation_type}[$number_instrumentation] = trim(substr($line,32,length($line)-33));
            $instrumentation{sectionnumber}[$number_instrumentation] = trim(substr($line,2,3));
            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Status\s*/i )            { $instrumentation{status}[$number_instrumentation] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i ) { $instrumentation{effective_dates}[$number_instrumentation] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $instrumentation{notes}[$number_instrumentation] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $instrumentation{notes}[$number_instrumentation] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 7.' . $instrumentation{sectionnumber}[$number_instrumentation] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 7.' . $instrumentation{sectionnumber}[$number_instrumentation] . '.'; }
          }
     }

  for($i=1;$i<=$number_instrumentation;$i++)
   {
      $instrumentation{notes}[$i]=~s/\'/&#39;/g;
      $instrumentation{notes}[$i]=~s/"/&#39;/g;
      $instrumentation{status}[$i] = uc($instrumentation{status}[$i]);

       # SECTION NUMBER
       if (($instrumentation{sectionnumber}[$i] - $i) > 0)
        {
         print('Section 7.' . $instrumentation{sectionnumber}[$i] . '' . "\n");
         print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
         $numbererrors++;
        }

      # INSTRUMENTATION TYPE
       if (
          (trim($instrumentation{instrumentation_type}[$i]) eq '' ) ||
          (trim($instrumentation{instrumentation_type}[$i]) eq '(GPS/GLONASS/DORIS/PRARE/SLR/VLBI/TIME/etc)' )
          )
        {
         print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Instrumentation Type : ' . $instrumentation{instrumentation_type}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
        }

      # STATUS
       if (
          (trim($instrumentation{status}[$i]) eq '' ) ||
          (trim($instrumentation{status}[$i]) eq '(PERMANENT/MOBILE)' )
          )
        {
         print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Status : ' . $instrumentation{status}[$i] . "\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
        }

       if (
          (trim($instrumentation{status}[$i]) ne '' ) &&
          (trim($instrumentation{status}[$i]) ne '(PERMANENT/MOBILE)' ) &&
          (trim($instrumentation{status}[$i]) ne 'PERMANENT' ) &&
          (trim($instrumentation{status}[$i]) ne 'MOBILE' )
          )
        {
         print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Status : ' . $instrumentation{status}[$i] . "\"\n");
         print('ERROR : invalid input. Please fill PERMANENT or MOBILE.' . "\n");
         $numbererrors++;
        }



       $error_effective_dates[$i] = '';


       # EFFECTIVE DATES
       if (
          (trim($instrumentation{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($instrumentation{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          )
        {
         print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\n");
         print('ERROR : complete at least the start date' . "\n");
         $error_effective_dates[$i] = 'true';
         $numbererrors++;
        }
       else
        {

          if (trim($instrumentation{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
           {
            if (substr($instrumentation{effective_dates}[$i],0,4) > $year)
             {
               print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],0,4) . ' is a senseless year in the start date' . "\n");
               $error_effective_dates[$i] = 'true';
               $numbererrors++;
             }

           if (substr($instrumentation{effective_dates}[$i],11,4) > $year)
             {
              print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],11,4) . ' is a senseless year in the end date' . "\n");
              $error_effective_dates[$i] = 'true';
              $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($instrumentation{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . "\n");
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($instrumentation{effective_dates}[$i],11,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . "\n");
               $numbererrors++;
             }


            # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
            if (
               ($error_effective_dates[$i] eq '') &&
               ( substr($instrumentation{effective_dates}[$i],0,10) gt substr($instrumentation{effective_dates}[$i],11,11) )
               )
             {
              print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
              print('ERROR : the start date precedes the end date' . "\n");
              $numbererrors++;
             }



           }


         if (trim($instrumentation{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          {
            if (substr($instrumentation{effective_dates}[$i],0,4) > $year)
             {
               print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],0,4) . ' is a senseless year in the start date' . "\n");
               $error_effective_dates[$i] = 'true';
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($instrumentation{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 7.' . $instrumentation{sectionnumber}[$i] . ' - "Effective Dates : ' . $instrumentation{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($instrumentation{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . "\n");
               $numbererrors++;
             }

          }


      }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 8 not found.'; }



  #######################################################################
  # READ SECTION 8.1
  #######################################################################
  $number_humiditysensor = 0;

  while ( ( $line !~ /^8.1.x\s*Humidity\s*Sensor\s*Model\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Humidity\s*Sensor\s*Model\s*/i ) && ($line !~ /\s*8.1.x\s*/i ) )
          {
            $number_humiditysensor++;
            $humiditysensor{model}[$number_humiditysensor] = trim(substr($line,32,length($line)-33));
            $humiditysensor{sectionnumber}[$number_humiditysensor] = trim(substr($line,4,3));
             while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Manufacturer\s*/i )               { $humiditysensor{manufacturer}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Serial\s*Number\s*/i )            { $humiditysensor{serial_number}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Data\s*Sampling\s*Interval\s*/i ) { $humiditysensor{data_sampling_interval}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Accuracy\s*\(\% rel h\)\s*/i )    { $humiditysensor{accuracy}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Aspiration\s*/i )                 { $humiditysensor{aspiration}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Height\s*Diff\s*to\s*Ant\s*/i )   { $humiditysensor{height_diff_to_ant}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Calibration\s*date\s*/i )         { $humiditysensor{calibration_date}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )          { $humiditysensor{effective_dates}[$number_humiditysensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $humiditysensor{notes}[$number_humiditysensor] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $humiditysensor{notes}[$number_humiditysensor] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.1.' . $humiditysensor{sectionnumber}[$number_humiditysensor] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.1.' . $humiditysensor{sectionnumber}[$number_humiditysensor] . '.'; }
          }
     }

  for($i=1;$i<=$number_humiditysensor;$i++)
   {
       $humiditysensor{model}[$i]=~s/\'/&#39;/g;
       $humiditysensor{model}[$i]=~s/"/&#39;/g;
       $humiditysensor{manufacturer}[$i]=~s/\'/&#39;/g;
       $humiditysensor{manufacturer}[$i]=~s/"/&#39;/g;
       $humiditysensor{data_sampling_interval}[$i] =~s/s$//;
       $humiditysensor{data_sampling_interval}[$i] =~s/sec$//;
       $humiditysensor{data_sampling_interval}[$i] =~s/SEC$//;
       $humiditysensor{data_sampling_interval}[$i] = trim($humiditysensor{data_sampling_interval}[$i]);
       $humiditysensor{accuracy}[$i] =~s/\(% rel h\)$//;
       $humiditysensor{accuracy}[$i] =~s/%rel h$//;
       $humiditysensor{accuracy}[$i] =~s/% rel h$//;
       $humiditysensor{accuracy}[$i] =~s/%$//;
       $humiditysensor{accuracy}[$i] =~s/\.$//;
       $humiditysensor{accuracy}[$i] =~s/^\./0./;
       $humiditysensor{accuracy}[$i] =~s/\+\/\-//;
       $humiditysensor{accuracy}[$i] = trim($humiditysensor{accuracy}[$i]);
       $humiditysensor{height_diff_to_ant}[$i] =~s/,/./g;
       $humiditysensor{height_diff_to_ant}[$i] =~s/M$//;
       $humiditysensor{height_diff_to_ant}[$i] =~s/m$//;
       $humiditysensor{height_diff_to_ant}[$i] =~ s/^\+//;
       $humiditysensor{height_diff_to_ant}[$i] = trim($humiditysensor{height_diff_to_ant}[$i]);
       $humiditysensor{notes}[$i] =~s/\'/&#39;/g;
       $humiditysensor{notes}[$i] =~s/"/&#39;/g;


       if (
          ($humiditysensor{model}[$i] ne '') or
          ($humiditysensor{manufacturer}[$i] ne '') or
          ($humiditysensor{serial_number}[$i] ne '') or
          ($humiditysensor{data_sampling_interval}[$i] ne '(sec)') or
          ($humiditysensor{accuracy}[$i] ne '') or                       #   (% rel h)
          ($humiditysensor{aspiration}[$i] ne '(UNASPIRATED/NATURAL/FAN/etc)') or
          ($humiditysensor{height_diff_to_ant}[$i] ne '(m)') or
          ($humiditysensor{calibration_date}[$i] ne '(CCYY-MM-DD)') or
          ($humiditysensor{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
          ($humiditysensor{notes}[$i] ne '(multiple lines)')
          )
      {
      }

     # SECTION NUMBER
     if (($humiditysensor{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }

     # MODEL
     if ( length(trim($humiditysensor{model}[$i])) == 0 )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Humidity Sensor Model : ' . $humiditysensor{model}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     # MANUFACTURER
     if ( length(trim($humiditysensor{manufacturer}[$i])) == 0 )
      {
         #print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Manufacturer : missing input' . "\n");
      }

     # SERIAL NUMBER
     if ( length(trim($humiditysensor{serial_number}[$i])) == 0 )
      {
         #print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Serial Number : missing input' . "\n");
      }

     # DATA SAMPLING INTERVAL
     if ( length(trim($humiditysensor{data_sampling_interval}[$i])) == 0 )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $humiditysensor{data_sampling_interval}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($humiditysensor{data_sampling_interval}[$i])) > 0 ) &&
        ($humiditysensor{data_sampling_interval}[$i] !~ /^[0-9]{1,}$/ )
        )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $humiditysensor{data_sampling_interval}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer.' . "\n");
         $numbererrors++;
      }

     # ACCURACY
     if ( length(trim($humiditysensor{accuracy}[$i])) == 0 )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Accuracy : ' . $humiditysensor{accuracy}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($humiditysensor{accuracy}[$i])) > 0 ) &&
        ($humiditysensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($humiditysensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Accuracy : ' . $humiditysensor{accuracy}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (may be preceded by "<").' . "\n");
         $numbererrors++;
      }

     # ASPIRATION
     if (
        (length(trim($humiditysensor{aspiration}[$i])) == 0 ) ||
        (trim($humiditysensor{aspiration}[$i]) eq '(UNASPIRATED/NATURAL/FAN/etc)')
        )
      {
         #print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - Aspiration : missing input' . "\n");
      }

     # HEIGHT DIFF TO ANT
     if ( length(trim($humiditysensor{height_diff_to_ant}[$i])) == 0 )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $humiditysensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($humiditysensor{height_diff_to_ant}[$i])) > 0 ) and
        ($humiditysensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($humiditysensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $humiditysensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float.' . "\n");
         $numbererrors++;
      }

     # CALIBRATION DATE
     if ($humiditysensor{calibration_date}[$i] !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
      {
         #print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - Calibration date : missing or invalid input' . "\n");
      }
     else
      {

        if ( (substr($humiditysensor{calibration_date}[$i],0,4) < 1800 ) || (substr($humiditysensor{calibration_date}[$i],0,4) > $year))
            {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Calibration date : ' . $humiditysensor{calibration_date}[$i] . "\"\n");
             print('ERROR : ' . substr($humiditysensor{calibration_date}[$i],0,4) . ' is a senseless year. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

        if (!(check_date(substr($humiditysensor{calibration_date}[$i],0,4), substr($humiditysensor{calibration_date}[$i],5,2), substr($humiditysensor{calibration_date}[$i],8,2))) )
            {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Calibration date : ' . $humiditysensor{calibration_date}[$i] . "\"\n");
             print('ERROR : invalid date. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }
      }



       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES (not for the LAST subsection)
       if (
          (trim($humiditysensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_humiditysensor)
          )
        {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($humiditysensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_humiditysensor)
          )
        {
         if (
            (substr($humiditysensor{effective_dates}[$i],0,4) < 1980 ) ||
            (substr($humiditysensor{effective_dates}[$i],0,4) > $year)
            )
           {
            print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($humiditysensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         if (
            (substr($humiditysensor{effective_dates}[$i],11,4) < 1980 ) ||
            (substr($humiditysensor{effective_dates}[$i],11,4) > $year)
            )
           {
            print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($humiditysensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         $error_effective_dates[$i] = check_stationlogdate(substr($humiditysensor{effective_dates}[$i],0,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
            print('ERROR : start date ' . substr($humiditysensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

         $error_effective_dates[$i] = check_stationlogdate(substr($humiditysensor{effective_dates}[$i],11,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
            print('ERROR : end date ' . substr($humiditysensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

       }

       # EFFECTIVE DATES (ONLY for the LAST subsection)

       if (
          (trim($humiditysensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          (trim($humiditysensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i == $number_humiditysensor)
          )
        {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start date is missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }


       if (
          (trim($humiditysensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_humiditysensor)
          )
        {
          if (
             (substr($humiditysensor{effective_dates}[$i],0,4) < 1980 ) ||
             (substr($humiditysensor{effective_dates}[$i],0,4) > $year)
             )
            {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($humiditysensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($humiditysensor{effective_dates}[$i],0,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
             print('ERROR : begin date ' . substr($humiditysensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }



       if (
          (trim($humiditysensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i == $number_humiditysensor)
          )
        {
          if (
             (substr($humiditysensor{effective_dates}[$i],11,4) < 1980 ) ||
             (substr($humiditysensor{effective_dates}[$i],11,4) > $year)
             )
            {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($humiditysensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($humiditysensor{effective_dates}[$i],11,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
             print('ERROR : end date ' . substr($humiditysensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }

       # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
       if (
          ($error_effective_dates[$i] eq '') &&
          ( substr($humiditysensor{effective_dates}[$i],0,10) gt substr($humiditysensor{effective_dates}[$i],11,11) )
          )
         {
           print('Section 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $humiditysensor{effective_dates}[$i] . "\"\n");
           print('ERROR : End Date (' . substr($humiditysensor{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($humiditysensor{effective_dates}[$i],0,10) . ')' . "\n");
           $numbererrors++;
         }

       # EFFECTIVE DATES (chronology comparison between Date Installed and ... Date Removed of the previous installation)
       if (
          ($error_effective_dates[$i] eq '') &&
          ($error_effective_dates[($i-1)] eq '') &&
          ( substr($humiditysensor{effective_dates}[$i],0,10) lt substr($humiditysensor{effective_dates}[($i-1)],11,11) )
          )
       {
         print('Section 8.1.' . $humiditysensor{sectionnumber}[($i-1)] . ' and 8.1.' . $humiditysensor{sectionnumber}[$i] . ' - "Effective Dates . ' . "\"\n");
         print('ERROR : Start Date (' . substr($humiditysensor{effective_dates}[$i],0,10) . ') precedes End Date (' . substr($humiditysensor{effective_dates}[($i-1)],11,11) . ')' . "\n");
         $numbererrors++;
       }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 8.1.x not found.'; }


  #######################################################################
  # READ SECTION 8.2
  #######################################################################
  $number_pressuresensor = 0;

  while ( ( $line !~ /^8.2.x\s*Pressure\s*Sensor\s*Model\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Pressure\s*Sensor\s*Model\s*/i ) && ($line !~ /\s*8.2.x\s*/i ) )
          {
            $number_pressuresensor++;
            $pressuresensor{model}[$number_pressuresensor] = trim(substr($line,32,length($line)-33));
            $pressuresensor{sectionnumber}[$number_pressuresensor] = trim(substr($line,4,3));
            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Manufacturer\s*/i )               { $pressuresensor{manufacturer}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Serial\s*Number\s*/i )            { $pressuresensor{serial_number}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Data\s*Sampling\s*Interval\s*/i ) { $pressuresensor{data_sampling_interval}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Accuracy\s*/i )                   { $pressuresensor{accuracy}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Height\s*Diff\s*to\s*Ant\s*/i )   { $pressuresensor{height_diff_to_ant}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Calibration\s*date\s*/i )         { $pressuresensor{calibration_date}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )          { $pressuresensor{effective_dates}[$number_pressuresensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $pressuresensor{notes}[$number_pressuresensor] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $pressuresensor{notes}[$number_pressuresensor] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.2.' . $pressuresensor{sectionnumber}[$number_pressuresensor] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.2.' . $pressuresensor{sectionnumber}[$number_pressuresensor] . '.'; }
          }
     }

  for($i=1;$i<=$number_pressuresensor;$i++)
   {
      $pressuresensor{model}[$i] =~s/\'/&#39;/g;
      $pressuresensor{model}[$i] =~s/"/&#39;/g;
      $pressuresensor{manufacturer}[$i] =~s/\'/&#39;/g;
      $pressuresensor{manufacturer}[$i] =~s/"/&#39;/g;
      $pressuresensor{data_sampling_interval}[$i] =~s/s$//;
      $pressuresensor{data_sampling_interval}[$i] =~s/sec$//;
      $pressuresensor{data_sampling_interval}[$i] =~s/SEC$//;
      $pressuresensor{data_sampling_interval}[$i] = trim($pressuresensor{data_sampling_interval}[$i]);
      $pressuresensor{accuracy}[$i] =~s/^\./0./;
      $pressuresensor{accuracy}[$i] =~s/\.$//;
      $pressuresensor{accuracy}[$i] =~s/hPa sigma$//;
      $pressuresensor{accuracy}[$i] =~s/hPa$//;
      $pressuresensor{accuracy}[$i] =~s/hpa$//;
      $pressuresensor{accuracy}[$i] =~s/hp$//;
      $pressuresensor{accuracy}[$i] =~s/\(mbar\)$//;
      $pressuresensor{accuracy}[$i] =~s/mbar$//;
      $pressuresensor{accuracy}[$i] =~s/mb$//;
      $pressuresensor{accuracy}[$i] =~s/\+\/\-//;
      $pressuresensor{accuracy}[$i] = trim($pressuresensor{accuracy}[$i]);
      $pressuresensor{height_diff_to_ant}[$i] =~s/\(m\)$//;
      $pressuresensor{height_diff_to_ant}[$i] =~s/m$//;
      $pressuresensor{height_diff_to_ant}[$i] =~ s/^\+//;
      $pressuresensor{height_diff_to_ant}[$i] =~s/,/./g;
      $pressuresensor{height_diff_to_ant}[$i] = trim($pressuresensor{height_diff_to_ant}[$i]);
      $pressuresensor{notes}[$i]=~s/\'/&#39;/g;
      $pressuresensor{notes}[$i]=~s/"/&#39;/g;

      if(
         ($pressuresensor{model}[$i] ne '') or
         ($pressuresensor{manufacturer}[$i] ne '') or
         ($pressuresensor{serial_number}[$i] ne '') or
         ($pressuresensor{data_sampling_interval}[$i] ne '(sec)') or
         ($pressuresensor{accuracy}[$i] ne '(hPa)') or
         ($pressuresensor{height_diff_to_ant}[$i] ne '') or    # (m)
         ($pressuresensor{calibration_date}[$i] ne '(CCYY-MM-DD)') or
         ($pressuresensor{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
         ($pressuresensor{notes}[$i] ne '(multiple lines)')
        )
      {
      }


     # SECTION NUMBER
     if (($pressuresensor{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }

     # MODEL
     if ( length(trim($pressuresensor{model}[$i])) == 0 )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Pressure Sensor Model : ' . $pressuresensor{model}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     # MANUFACTURER
     if ( length(trim($pressuresensor{manufacturer}[$i])) == 0 )
      {
         #print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Manufacturer : missing input' . "\n");
      }

     # SERIAL NUMBER
     if ( length(trim($pressuresensor{serial_number}[$i])) == 0 )
      {
         #print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Serial Number : missing input' . "\n");
      }

     # DATA SAMPLING INTERVAL
     if ( length(trim($pressuresensor{data_sampling_interval}[$i])) == 0 )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $pressuresensor{data_sampling_interval}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($pressuresensor{data_sampling_interval}[$i])) > 0 ) &&
        ($pressuresensor{data_sampling_interval}[$i] !~ /^[0-9]{1,}$/ )
        )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $pressuresensor{data_sampling_interval}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer.' . "\n");
         $numbererrors++;
      }

     # ACCURACY
     if ( length(trim($pressuresensor{accuracy}[$i])) == 0 )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Accuracy : ' . $pressuresensor{accuracy}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($pressuresensor{accuracy}[$i])) > 0 ) &&
        ($pressuresensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($pressuresensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Accuracy : ' . $pressuresensor{accuracy}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (may be preceded by "<").' . "\n");
         $numbererrors++;
      }

     # HEIGHT DIFF TO ANT
     if ( length(trim($pressuresensor{height_diff_to_ant}[$i])) == 0 )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $pressuresensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($pressuresensor{height_diff_to_ant}[$i])) > 0 ) and
        ($pressuresensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($pressuresensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $pressuresensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float.' . "\n");
         $numbererrors++;
      }

     # CALIBRATION DATE
     if ($pressuresensor{calibration_date}[$i] !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
      {
         #print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - Calibration date : missing or invalid input' . "\n");
      }
     else
      {

        if ( (substr($pressuresensor{calibration_date}[$i],0,4) < 1800 ) || (substr($pressuresensor{calibration_date}[$i],0,4) > $year))
            {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Calibration date : ' . $pressuresensor{calibration_date}[$i] . "\"\n");
             print('ERROR : ' . substr($pressuresensor{calibration_date}[$i],0,4) . ' is a senseless year. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

        if (!(check_date(substr($pressuresensor{calibration_date}[$i],0,4), substr($pressuresensor{calibration_date}[$i],5,2), substr($pressuresensor{calibration_date}[$i],8,2))) )
            {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Calibration date : ' . $pressuresensor{calibration_date}[$i] . "\"\n");
             print('ERROR : invalid date. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }
      }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES (not for the LAST subsection)
       if (
          (trim($pressuresensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_pressuresensor)
          )
        {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($pressuresensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_pressuresensor)
          )
        {
         if (
            (substr($pressuresensor{effective_dates}[$i],0,4) < 1980 ) ||
            (substr($pressuresensor{effective_dates}[$i],0,4) > $year)
            )
           {
            print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($pressuresensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         if (
            (substr($pressuresensor{effective_dates}[$i],11,4) < 1980 ) ||
            (substr($pressuresensor{effective_dates}[$i],11,4) > $year)
            )
           {
            print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($pressuresensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         $error_effective_dates[$i] = check_stationlogdate(substr($pressuresensor{effective_dates}[$i],0,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
            print('ERROR : start date ' . substr($pressuresensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

         $error_effective_dates[$i] = check_stationlogdate(substr($pressuresensor{effective_dates}[$i],11,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
            print('ERROR : end date ' . substr($pressuresensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;

          }

       }

       # EFFECTIVE DATES (ONLY for the LAST subsection)
       if (
          (trim($pressuresensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          (trim($pressuresensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i == $number_pressuresensor)
          )
        {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start date is missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($pressuresensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_pressuresensor)
          )
        {
          if (
             (substr($pressuresensor{effective_dates}[$i],0,4) < 1980 ) ||
             (substr($pressuresensor{effective_dates}[$i],0,4) > $year)
             )
            {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($pressuresensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($pressuresensor{effective_dates}[$i],0,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
             print('ERROR : begin date ' . substr($pressuresensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }



       if (
          (trim($pressuresensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i == $number_pressuresensor)
          )
        {
          if (
             (substr($pressuresensor{effective_dates}[$i],11,4) < 1980 ) ||
             (substr($pressuresensor{effective_dates}[$i],11,4) > $year)
             )
            {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($pressuresensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($pressuresensor{effective_dates}[$i],11,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
             print('ERROR : end date ' . substr($pressuresensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }





       # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
       if (
          ($error_effective_dates[$i] eq '') &&
          ( substr($pressuresensor{effective_dates}[$i],0,10) gt substr($pressuresensor{effective_dates}[$i],11,11) )
          )
         {
           print('Section 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $pressuresensor{effective_dates}[$i] . "\"\n");
           print('ERROR : End Date (' . substr($pressuresensor{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($pressuresensor{effective_dates}[$i],0,10) . ')' . "\n");
           $numbererrors++;
         }

       # EFFECTIVE DATES (chronology comparison between Date Installed and ... Date Removed of the previous installation)
       if (
          ($error_effective_dates[$i] eq '') &&
          ($error_effective_dates[($i-1)] eq '') &&
          ( substr($pressuresensor{effective_dates}[$i],0,10) lt substr($pressuresensor{effective_dates}[($i-1)],11,11) )
          )
       {
         print('Section 8.2.' . $pressuresensor{sectionnumber}[($i-1)] . ' and 8.2.' . $pressuresensor{sectionnumber}[$i] . ' - "Effective Dates . ' . "\"\n");
         print('ERROR : Start Date (' . substr($pressuresensor{effective_dates}[$i],0,10) . ') precedes End Date (' . substr($pressuresensor{effective_dates}[($i-1)],11,11) . ')' . "\n");
         $numbererrors++;
       }

   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 8.2.x not found.'; }


  #######################################################################
  # READ SECTION 8.3
  #######################################################################
  $number_temperaturesensor = 0;

  while ( ( $line !~ /^8.3.x\s*Temp.\s*Sensor\s*Model\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Temp.\s*Sensor\s*Model\s*/i ) && ($line !~ /\s*8.3.x\s*/i ) )
          {
            $number_temperaturesensor++;
            $temperaturesensor{model}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33));
            $temperaturesensor{sectionnumber}[$number_temperaturesensor] = trim(substr($line,4,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Manufacturer\s*/i )               { $temperaturesensor{manufacturer}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Serial\s*Number\s*/i )            { $temperaturesensor{serial_number}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Data\s*Sampling\s*Interval\s*/i ) { $temperaturesensor{data_sampling_interval}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Accuracy\s*/i )                   { $temperaturesensor{accuracy}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Aspiration\s*/i )                 { $temperaturesensor{aspiration}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Height\s*Diff\s*to\s*Ant\s*/i )   { $temperaturesensor{height_diff_to_ant}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Calibration\s*date\s*/i )         { $temperaturesensor{calibration_date}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )          { $temperaturesensor{effective_dates}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $temperaturesensor{notes}[$number_temperaturesensor] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $temperaturesensor{notes}[$number_temperaturesensor] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.3.' . $temperaturesensor{sectionnumber}[$number_temperaturesensor] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.3.' . $temperaturesensor{sectionnumber}[$number_temperaturesensor] . '.'; }
          }
     }

  for($i=1;$i<=$number_temperaturesensor;$i++)
   {
      $temperaturesensor{model}[$i]=~s/\'/&#39;/g;
      $temperaturesensor{model}[$i]=~s/"/&#39;/g;
      $temperaturesensor{manufacturer}[$i] =~s/\'/&#39;/g;
      $temperaturesensor{manufacturer}[$i] =~s/"/&#39;/g;
      $temperaturesensor{data_sampling_interval}[$i] =~s/s$//;
      $temperaturesensor{data_sampling_interval}[$i] =~s/sec$//;
      $temperaturesensor{data_sampling_interval}[$i] =~s/SEC$//;
      $temperaturesensor{data_sampling_interval}[$i] = trim($temperaturesensor{data_sampling_interval}[$i]);
      $temperaturesensor{accuracy}[$i] =~s/^\./0./;
      $temperaturesensor{accuracy}[$i] =~s/\.$//;
      $temperaturesensor{accuracy}[$i] =~s/\(deg C\)$//;
      $temperaturesensor{accuracy}[$i] =~s/deg C$//;
      $temperaturesensor{accuracy}[$i] =~s/deg.C$//;
      $temperaturesensor{accuracy}[$i] =~s/\°C$//;
      $temperaturesensor{accuracy}[$i] =~s/C$//;
      $temperaturesensor{accuracy}[$i] =~s/\+\/\-//;
      $temperaturesensor{accuracy}[$i] = trim($temperaturesensor{accuracy}[$i]);
      $temperaturesensor{height_diff_to_ant}[$i] =~s/m$//;
      $temperaturesensor{height_diff_to_ant}[$i] =~ s/^\+//;
      $temperaturesensor{height_diff_to_ant}[$i] =~s/,/./g;
      $temperaturesensor{height_diff_to_ant}[$i] = trim($temperaturesensor{height_diff_to_ant}[$i]);
      $temperaturesensor{notes}[$i]=~s/\'/&#39;/g;
      $temperaturesensor{notes}[$i]=~s/"/&#39;/g;

      if (
         ($temperaturesensor{model}[$i] ne '') or
         ($temperaturesensor{manufacturer}[$i] ne '') or
         ($temperaturesensor{serial_number}[$i] ne '') or
         ($temperaturesensor{data_sampling_interval}[$i] ne '(sec)') or
         ($temperaturesensor{accuracy}[$i] ne '') or
         ($temperaturesensor{aspiration}[$i] ne '(UNASPIRATED/NATURAL/FAN/etc)') or
         ($temperaturesensor{height_diff_to_ant}[$i] ne '(m)') or
         ($temperaturesensor{calibration_date}[$i] ne '(CCYY-MM-DD)') or
         ($temperaturesensor{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
         ($temperaturesensor{notes}[$i] ne '(multiple lines)')
        )
      {
      }

     # SECTION NUMBER
     if (($temperaturesensor{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }

     # MODEL
     if ( length(trim($temperaturesensor{model}[$i])) == 0 )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Temperature Sensor Model : ' . $temperaturesensor{model}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     # MANUFACTURER
     if ( length(trim($temperaturesensor{manufacturer}[$i])) == 0 )
      {
         #print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Manufacturer : missing input' . "\n");
      }

     # SERIAL NUMBER
     if ( length(trim($temperaturesensor{serial_number}[$i])) == 0 )
      {
         #print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Serial Number : missing input' . "\n");
      }

     # DATA SAMPLING INTERVAL
     if ( length(trim($temperaturesensor{data_sampling_interval}[$i])) == 0 )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $temperaturesensor{data_sampling_interval}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($temperaturesensor{data_sampling_interval}[$i])) > 0 ) &&
        ($temperaturesensor{data_sampling_interval}[$i] !~ /^[0-9]{1,}$/ )
        )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Data Sampling Interval : ' . $temperaturesensor{data_sampling_interval}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer.' . "\n");
         $numbererrors++;
      }

     # ACCURACY
     if ( length(trim($temperaturesensor{accuracy}[$i])) == 0 )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Accuracy : ' . $temperaturesensor{accuracy}[$i] . "\"\n");
         print('WARNING : missing input (recommended).' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($temperaturesensor{accuracy}[$i])) > 0 ) &&
        ($temperaturesensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($temperaturesensor{accuracy}[$i] !~ /^<{0,1}\s{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Accuracy : ' . $temperaturesensor{accuracy}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float (may be preceded by "<").' . "\n");
         $numbererrors++;
      }

     # ASPIRATION
     if (
        (length(trim($temperaturesensor{aspiration}[$i])) == 0 ) ||
        (trim($temperaturesensor{aspiration}[$i]) eq '(UNASPIRATED/NATURAL/FAN/etc)')
        )
      {
         #print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Aspiration : missing input' . "\n");
      }

     # HEIGHT DIFF TO ANT
     if ( length(trim($temperaturesensor{height_diff_to_ant}[$i])) == 0 )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $temperaturesensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($temperaturesensor{height_diff_to_ant}[$i])) > 0 ) and
        ($temperaturesensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($temperaturesensor{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $temperaturesensor{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float.' . "\n");
         $numbererrors++;
      }

     # CALIBRATION DATE
     if ($temperaturesensor{calibration_date}[$i] !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
      {
         #print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - Calibration date : missing or invalid input' . "\n");
      }
     else
      {

        if ( (substr($temperaturesensor{calibration_date}[$i],0,4) < 1800 ) || (substr($temperaturesensor{calibration_date}[$i],0,4) > $year))
            {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Calibration date : ' . $temperaturesensor{calibration_date}[$i] . "\"\n");
             print('ERROR : ' . substr($temperaturesensor{calibration_date}[$i],0,4) . ' is a senseless year. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

        if (!(check_date(substr($temperaturesensor{calibration_date}[$i],0,4), substr($temperaturesensor{calibration_date}[$i],5,2), substr($temperaturesensor{calibration_date}[$i],8,2))) )
            {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Calibration date : ' . $temperaturesensor{calibration_date}[$i] . "\"\n");
             print('ERROR : invalid date. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

      }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES (not for the LAST subsection)
       if (
          (trim($temperaturesensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_temperaturesensor)
          )
        {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($temperaturesensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_temperaturesensor)
          )
        {
         if (
            (substr($temperaturesensor{effective_dates}[$i],0,4) < 1980 ) ||
            (substr($temperaturesensor{effective_dates}[$i],0,4) > $year)
            )
           {
            print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($temperaturesensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         if (
            (substr($temperaturesensor{effective_dates}[$i],11,4) < 1980 ) ||
            (substr($temperaturesensor{effective_dates}[$i],11,4) > $year)
            )
           {
            print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($temperaturesensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         $error_effective_dates[$i] = check_stationlogdate(substr($temperaturesensor{effective_dates}[$i],0,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
            print('ERROR : start date ' . substr($temperaturesensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

         $error_effective_dates[$i] = check_stationlogdate(substr($temperaturesensor{effective_dates}[$i],11,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
            print('ERROR : end date ' . substr($temperaturesensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

       }

       # EFFECTIVE DATES (ONLY for the LAST subsection)
       if (
          (trim($temperaturesensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($temperaturesensor{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_temperaturesensor)
          )
        {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
         print('ERROR : start date is missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($temperaturesensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_temperaturesensor)
          )
        {

          if (
             (substr($temperaturesensor{effective_dates}[$i],0,4) < 1980 ) ||
             (substr($temperaturesensor{effective_dates}[$i],0,4) > $year)
             )
            {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($temperaturesensor{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($temperaturesensor{effective_dates}[$i],0,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
             print('ERROR : begin date ' . substr($temperaturesensor{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }


       if (
          (trim($temperaturesensor{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i == $number_temperaturesensor)
          )
        {
          if (
             (substr($temperaturesensor{effective_dates}[$i],11,4) < 1980 ) ||
             (substr($temperaturesensor{effective_dates}[$i],11,4) > $year)
             )
            {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($temperaturesensor{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($temperaturesensor{effective_dates}[$i],11,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
             print('ERROR : end date ' . substr($temperaturesensor{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }





       # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
       if (
          ($error_effective_dates[$i] eq '') &&
          ( substr($temperaturesensor{effective_dates}[$i],0,10) gt substr($temperaturesensor{effective_dates}[$i],11,11) )
          )
         {
           print('Section 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates : ' . $temperaturesensor{effective_dates}[$i] . "\"\n");
           print('ERROR : End Date (' . substr($temperaturesensor{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($temperaturesensor{effective_dates}[$i],0,10) . ')' . "\n");
           $numbererrors++;
         }

       # EFFECTIVE DATES (chronology comparison between Date Installed and ... Date Removed of the previous installation)
       if (
          ($error_effective_dates[$i] eq '') &&
          ($error_effective_dates[($i-1)] eq '') &&
          ( substr($temperaturesensor{effective_dates}[$i],0,10) lt substr($temperaturesensor{effective_dates}[($i-1)],11,11) )
          )
       {
         print('Section 8.3.' . $temperaturesensor{sectionnumber}[($i-1)] . ' and 8.3.' . $temperaturesensor{sectionnumber}[$i] . ' - "Effective Dates . ' . "\"\n");
         print('ERROR : Start Date (' . substr($temperaturesensor{effective_dates}[$i],0,10) . ') precedes End Date (' . substr($temperaturesensor{effective_dates}[($i-1)],11,11) . ')' . "\n");
         $numbererrors++;
       }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 8.3.x not found.'; }





  #######################################################################
  # READ SECTION 8.4
  #######################################################################
  $number_watervaporradiometer = 0;

  while ( ( $line !~ /^8.4.x\s*Water\s*Vapor\s*Radiometer\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Water\s*Vapor\s*Radiometer\s*/i ) && ($line !~ /\s*8.4.x\s*/i ) )
          {
            $number_watervaporradiometer++;
            $watervaporradiometer{model}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33));
            $watervaporradiometer{sectionnumber}[$number_watervaporradiometer] = trim(substr($line,4,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Manufacturer\s*/i )               { $watervaporradiometer{manufacturer}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Serial\s*Number\s*/i )            { $watervaporradiometer{serial_number}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Distance\s*to\s*Antenna\s*/i )    { $watervaporradiometer{distance_to_antenna}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Height\s*Diff\s*to\s*Ant\s*/i )   { $watervaporradiometer{height_diff_to_ant}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Calibration\s*date\s*/i )         { $watervaporradiometer{calibration_date}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )          { $watervaporradiometer{effective_dates}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Notes\s*/i )
                 {
                  $watervaporradiometer{notes}[$number_watervaporradiometer] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $watervaporradiometer{notes}[$number_watervaporradiometer] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.4.' . $watervaporradiometer{sectionnumber}[$number_watervaporradiometer] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.4.' . $watervaporradiometer{sectionnumber}[$number_watervaporradiometer] . '.'; }
          }
     }

  for($i=1;$i<=$number_watervaporradiometer;$i++)
   {
      $watervaporradiometer{model}[$i] =~s/\'/&#39;/g;
      $watervaporradiometer{model}[$i] =~s/"/&#39;/g;
      $watervaporradiometer{manufacturer}[$i] =~s/\'/&#39;/g;
      $watervaporradiometer{manufacturer}[$i] =~s/"/&#39;/g;
      $watervaporradiometer{height_diff_to_ant}[$i] =~s/m$//;
      $watervaporradiometer{height_diff_to_ant}[$i] =~s/,/./g;
      $watervaporradiometer{height_diff_to_ant}[$i] =~s/^\+//;
      $watervaporradiometer{height_diff_to_ant}[$i] = trim($watervaporradiometer{height_diff_to_ant}[$i]);
      $watervaporradiometer{distance_to_antenna}[$i] =~s/m$//;
      $watervaporradiometer{distance_to_antenna}[$i] =~s/,/./g;
      $watervaporradiometer{distance_to_antenna}[$i] =~s/^\+//;
      $watervaporradiometer{distance_to_antenna}[$i] = trim($watervaporradiometer{distance_to_antenna}[$i]);
      $watervaporradiometer{notes}[$i] =~s/\'/&#39;/g;
      $watervaporradiometer{notes}[$i] =~s/"/&#39;/g;

      if(
        ($watervaporradiometer{model}[$i] ne '') or
        ($watervaporradiometer{manufacturer}[$i] ne '') or
        ($watervaporradiometer{serial_number}[$i] ne '') or
        ($watervaporradiometer{distance_to_antenna}[$i] ne '(m)') or
        ($watervaporradiometer{height_diff_to_ant}[$i] ne '(m)') or
        ($watervaporradiometer{calibration_date}[$i] ne '(CCYY-MM-DD)') or
        ($watervaporradiometer{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
        ($watervaporradiometer{notes}[$i] ne '(multiple lines)')
        )
      {
      }

     # SECTION NUMBER
     if (($watervaporradiometer{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }


     # WATER VAPOR RADIOMETER - MODEL
     if ( length(trim($watervaporradiometer{model}[$i])) == 0 )
      {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Water Vapor Radiometer : ' . $watervaporradiometer{model}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     # MANUFACTURER
     if ( length(trim($watervaporradiometer{manufacturer}[$i])) == 0 )
      {
         #print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - Manufacturer : missing input' . "\n");
      }

     # SERIAL NUMBER
     if ( length(trim($watervaporradiometer{serial_number}[$i])) == 0 )
      {
         #print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - Serial Number : missing input' . "\n");
      }

     # DISTANCE TO ANTENNA
     if ( length(trim($watervaporradiometer{distance_to_antenna}[$i])) == 0 )
      {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Distance to Antenna : ' . $watervaporradiometer{distance_to_antenna}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($watervaporradiometer{distance_to_antenna}[$i])) > 0 ) and
        ($watervaporradiometer{distance_to_antenna}[$i] !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($watervaporradiometer{distance_to_antenna}[$i] !~ /^[-]{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Distance to Antenna : ' . $watervaporradiometer{distance_to_antenna}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float' . "\n");
         $numbererrors++;
      }

     # HEIGHT DIFF TO ANT
     if ( length(trim($watervaporradiometer{height_diff_to_ant}[$i])) == 0 )
      {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $watervaporradiometer{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     if (
        ( length(trim($watervaporradiometer{height_diff_to_ant}[$i])) > 0 ) and
        ($watervaporradiometer{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}\.[0-9]{1,}$/ ) &&
        ($watervaporradiometer{height_diff_to_ant}[$i] !~ /^[-]{0,1}[0-9]{1,}$/ )
        )
      {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Height Diff to Ant : ' . $watervaporradiometer{height_diff_to_ant}[$i] . "\"\n");
         print('ERROR : invalid format. Use integer or float.' . "\n");
         $numbererrors++;
      }

     # CALIBRATION DATE
     if ($watervaporradiometer{calibration_date}[$i] !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
      {
         #print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - Calibration date : missing or invalid input' . "\n");
      }
     else
      {

        if ( (substr($watervaporradiometer{calibration_date}[$i],0,4) < 1800 ) || (substr($watervaporradiometer{calibration_date}[$i],0,4) > $year))
            {
             print('Section 8.1.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Calibration date : ' . $watervaporradiometer{calibration_date}[$i] . "\"\n");
             print('ERROR : ' . substr($watervaporradiometer{calibration_date}[$i],0,4) . ' is a senseless year. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

        if (!(check_date(substr($watervaporradiometer{calibration_date}[$i],0,4), substr($watervaporradiometer{calibration_date}[$i],5,2), substr($watervaporradiometer{calibration_date}[$i],8,2))) )
            {
             print('Section 8.1.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Calibration date : ' . $watervaporradiometer{calibration_date}[$i] . "\"\n");
             print('ERROR : invalid date. Use CCYY-MM-DD.' . "\n");
             $numbererrors++;
            }

      }

       $error_effective_dates[$i] = '';


       # EFFECTIVE DATES (not for the LAST subsection)
       if (
          (trim($watervaporradiometer{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_watervaporradiometer)
          )
        {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($watervaporradiometer{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          ($i < $number_watervaporradiometer)
          )
        {
         if (
            (substr($watervaporradiometer{effective_dates}[$i],0,4) < 1980 ) ||
            (substr($watervaporradiometer{effective_dates}[$i],0,4) > $year)
            )
           {
            print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($watervaporradiometer{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         if (
            (substr($watervaporradiometer{effective_dates}[$i],11,4) < 1980 ) ||
            (substr($watervaporradiometer{effective_dates}[$i],11,4) > $year)
            )
           {
            print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
            print('ERROR : ' . substr($watervaporradiometer{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
            $error_effective_dates[$i] = 'true';
           }

         $error_effective_dates[$i] = check_stationlogdate(substr($watervaporradiometer{effective_dates}[$i],0,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
            print('ERROR : start date ' . substr($watervaporradiometer{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

         $error_effective_dates[$i] = check_stationlogdate(substr($watervaporradiometer{effective_dates}[$i],11,10));
         if($error_effective_dates[$i] ne '')
          {
            print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
            print('ERROR : end date ' . substr($watervaporradiometer{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
            $numbererrors++;
          }

       }

       # EFFECTIVE DATES (ONLY for the LAST subsection)
       if (
          (trim($watervaporradiometer{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_watervaporradiometer)
          )
        {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
         print('ERROR : start date is missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }

       if (
          (trim($watervaporradiometer{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ ) &&
          ($i == $number_watervaporradiometer)
          )
        {
          if (
             (substr($watervaporradiometer{effective_dates}[$i],0,4) < 1980 ) ||
             (substr($watervaporradiometer{effective_dates}[$i],0,4) > $year)
             )
            {
             print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
             print('ERROR : ' . substr($watervaporradiometer{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
             $error_effective_dates[$i] = 'true';
            }


          $error_effective_dates[$i] = check_stationlogdate(substr($watervaporradiometer{effective_dates}[$i],0,10));
          if($error_effective_dates[$i] ne '')
           {
             print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
             print('ERROR : begin date ' . substr($watervaporradiometer{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
             $numbererrors++;
           }
       }

       # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
       if (
          ($error_effective_dates[$i] eq '') &&
          ( substr($watervaporradiometer{effective_dates}[$i],0,10) gt substr($watervaporradiometer{effective_dates}[$i],11,11) )
          )
         {
           print('Section 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates : ' . $watervaporradiometer{effective_dates}[$i] . "\"\n");
           print('ERROR : End Date (' . substr($watervaporradiometer{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($watervaporradiometer{effective_dates}[$i],0,10) . ')' . "\n");
           $numbererrors++;
         }

       # EFFECTIVE DATES (chronology comparison between Date Installed and ... Date Removed of the previous installation)
       if (
          ($error_effective_dates[$i] eq '') &&
          ($error_effective_dates[($i-1)] eq '') &&
          ( substr($watervaporradiometer{effective_dates}[$i],0,10) lt substr($watervaporradiometer{effective_dates}[($i-1)],11,11) )
          )
       {
         print('Section 8.4.' . $watervaporradiometer{sectionnumber}[($i-1)] . ' and 8.4.' . $watervaporradiometer{sectionnumber}[$i] . ' - "Effective Dates . ' . "\"\n");
         print('ERROR : Start Date (' . substr($watervaporradiometer{effective_dates}[$i],0,10) . ') precedes End Date (' . substr($watervaporradiometer{effective_dates}[($i-1)],11,11) . ')' . "\n");
         $numbererrors++;
       }



   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 8.4.x not found.'; }



  #######################################################################
  # READ SECTION 8.5
  #######################################################################
  $number_otherinstrumentation = 0;

  while ( ( $line !~ /^9.\s*Local\s*Ongoing\s*Conditions\s*Possibly\s*Affecting\s*Computed\s*Position\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Other\s*Instrumentation\s*/i ) && ($line !~ /\s*8.5.x\s*/i ) )
          {
            $number_otherinstrumentation++;
            $otherinstrumentation[$number_otherinstrumentation] = trim(substr($line,32,length($line)-33));
            $otherinstrumentation_sectionnumber[$number_otherinstrumentation] = trim(substr($line,4,3));

            $line = <LogFile>;
            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $otherinstrumentation[$number_otherinstrumentation] .= "\n" . trim(substr($line,32,length($line)-33));
                 $line = <LogFile>;
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 8.5.' . $otherinstrumentation_sectionnumber[$number_otherinstrumentation] . '.'; }
          }
     }

  for($i=1;$i<=$number_otherinstrumentation;$i++)
   {
     $otherinstrumentation[$i] =~s/\'/&#39;/g;
     $otherinstrumentation[$i] =~s/"/&#39;/g;

     if ($otherinstrumentation[$i] ne '(multiple lines)')
     {
     }

     # SECTION NUMBER
     if (($otherinstrumentation_sectionnumber[$i] - $i) > 0)
      {
       print('Section 8.5.' . $otherinstrumentation_sectionnumber[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }


     # OTHER INSTRUMENTATION
     if ( length(trim($otherinstrumentation[$i])) == 0 )
      {
         print('Section 8.5.' . $otherinstrumentation_sectionnumber[$i] . ' - "Other Instrumentation : ' . $otherinstrumentation[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 9 not found.'; }



  #######################################################################
  # READ SECTION 9.1
  #######################################################################
  $number_radiointerferences = 0;

  while ( ( $line !~ /^9.1.x\s*Radio\s*Interferences\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Radio\s*Interferences\s*/i ) && ($line !~ /\s*9.1.x\s*/i ) )
          {
            $number_radiointerferences++;
            $radiointerferences{radiointerferences}[$number_radiointerferences] = trim(substr($line,32,length($line)-33));
            $radiointerferences{sectionnumber}[$number_radiointerferences] = trim(substr($line,4,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;
                 if ( (substr($line,0,32) =~ /\s*Observed\s*Degradations\s*/i ) || (substr($line,0,32) =~ /\s*Observed\s*Degredations\s*/i ) ) { $radiointerferences{observed_degradations}[$number_radiointerferences] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )       { $radiointerferences{effective_dates}[$number_radiointerferences] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $radiointerferences{additional_information}[$number_radiointerferences] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $radiointerferences{additional_information}[$number_radiointerferences] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.1.' . $radiointerferences{sectionnumber}[$number_radiointerferences] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.1.' . $radiointerferences{sectionnumber}[$number_radiointerferences] . '.'; }
          }
     }

  for($i=1;$i<=$number_radiointerferences;$i++)
   {
     $radiointerferences{additional_information}[$i] =~s/\'/&#39;/g;
     $radiointerferences{additional_information}[$i] =~s/"/&#39;/g;

     if (
         ($radiointerferences{radiointerferences}[$i] ne '(TV/CELL PHONE ANTENNA/RADAR/etc)') or
         ($radiointerferences{observed_degradations}[$i] ne '(SN RATIO/DATA GAPS/etc)') or
         ($radiointerferences{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
         ($radiointerferences{additional_information}[$i] ne '(multiple lines)')
        )
     {
     }

     # SECTION NUMBER
     if (($radiointerferences{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }

     # RADIO INTERFERENCES - ORIGIN
     if ( ( length(trim($radiointerferences{radiointerferences}[$i])) == 0 ) || (trim($radiointerferences{radiointerferences}[$i]) eq '(TV/CELL PHONE ANTENNA/RADAR/etc)' ) )
      {
         print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Radio Interferences : ' . $radiointerferences{radiointerferences}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }

     # OBSERVED DEGRADATIONS
     if ( ( length(trim($radiointerferences{observed_degradations}[$i])) == 0 ) || (trim($radiointerferences{observed_degradations}[$i]) eq '(TV/CELL PHONE ANTENNA/RADAR/etc)' ) )
      {
         print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Observed Degradations : ' . $radiointerferences{observed_degradations}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES
       if (
          (trim($radiointerferences{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($radiointerferences{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          )
        {
         print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }
       else
        {

          if (trim($radiointerferences{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
           {
            if (
               (substr($radiointerferences{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($radiointerferences{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($radiointerferences{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

           if (
              (substr($radiointerferences{effective_dates}[$i],11,4) < 1980 ) ||
              (substr($radiointerferences{effective_dates}[$i],11,4) > $year)
              )
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($radiointerferences{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($radiointerferences{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($radiointerferences{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($radiointerferences{effective_dates}[$i],11,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : end date ' . substr($radiointerferences{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }


            # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
            if (
               ($error_effective_dates[$i] eq '') &&
               ( substr($radiointerferences{effective_dates}[$i],0,10) gt substr($radiointerferences{effective_dates}[$i],11,11) )
               )
             {
              print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
              print('ERROR : End Date (' . substr($radiointerferences{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($radiointerferences{effective_dates}[$i],0,10) . ')' . "\n");
              $numbererrors++;
             }



           }


         if (trim($radiointerferences{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          {
            if (
               (substr($radiointerferences{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($radiointerferences{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($radiointerferences{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($radiointerferences{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.1.' . $radiointerferences{sectionnumber}[$i] . ' - "Effective Dates : ' . $radiointerferences{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($radiointerferences{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

          }


      }



   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 9.1.x not found.'; }


  #######################################################################
  # READ SECTION 9.2
  #######################################################################
  $number_multipathsources = 0;

  while ( ( $line !~ /^9.2.x\s*Multipath\s*Sources\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Multipath\s*Sources\s*/i ) && ($line !~ /\s*9.2.x\s*/i ) )
          {
            $number_multipathsources++;
            $multipathsources{multipathsources}[$number_multipathsources] = trim(substr($line,32,length($line)-33));
            $multipathsources{sectionnumber}[$number_multipathsources] = trim(substr($line,4,3));

            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )        { $multipathsources{effective_dates}[$number_multipathsources] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $multipathsources{additional_information}[$number_multipathsources] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $multipathsources{additional_information}[$number_multipathsources] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.2.' . $multipathsources{sectionnumber}[$number_multipathsources] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.2.' . $multipathsources{sectionnumber}[$number_multipathsources] . '.'; }
          }
     }

  for($i=1;$i<=$number_multipathsources;$i++)
   {
     $multipathsources{additional_information}[$i] =~s/\'/&#39;/g;
     $multipathsources{additional_information}[$i] =~s/"/&#39;/g;

     if (
         ($multipathsources{multipathsources}[$i] ne '(METAL ROOF/DOME/VLBI ANTENNA/etc)') or
         ($multipathsources{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
         ($multipathsources{additional_information}[$i] ne '(multiple lines)')
         )
      {
      }

     # SECTION NUMBER
     if (($multipathsources{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }


     # MULTIPATH SOURCES - ORIGIN
     if ( ( length(trim($multipathsources{multipathsources}[$i])) == 0 ) || (trim($multipathsources{multipathsources}[$i]) eq '(METAL ROOF/DOME/VLBI ANTENNA/etc)' ) )
      {
         print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Multipath Sources : ' . $multipathsources{multipathsources}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES
       if (
          (trim($multipathsources{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($multipathsources{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          )
        {
         print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }
       else
        {

          if (trim($multipathsources{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
           {
            if (
               (substr($multipathsources{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($multipathsources{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($multipathsources{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

           if (
              (substr($multipathsources{effective_dates}[$i],11,4) < 1980 ) ||
              (substr($multipathsources{effective_dates}[$i],11,4) > $year)
              )
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($multipathsources{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }



            $error_effective_dates[$i] = check_stationlogdate(substr($multipathsources{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($multipathsources{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($multipathsources{effective_dates}[$i],11,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : end date ' . substr($multipathsources{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }


            # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
            if (
               ($error_effective_dates[$i] eq '') &&
               ( substr($multipathsources{effective_dates}[$i],0,10) gt substr($multipathsources{effective_dates}[$i],11,11) )
               )
             {
              print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
              print('ERROR : End Date (' . substr($multipathsources{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($multipathsources{effective_dates}[$i],0,10) . ')' . "\n");
              $numbererrors++;
             }



           }


         if (trim($multipathsources{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          {
            if (
               (substr($multipathsources{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($multipathsources{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($multipathsources{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($multipathsources{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.2.' . $multipathsources{sectionnumber}[$i] . ' - "Effective Dates : ' . $multipathsources{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($multipathsources{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

          }


      }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 9.2.x not found.'; }


  #######################################################################
  # READ SECTION 9.3
  #######################################################################
  $number_signalobstructions = 0;
  while ( ( $line !~ /^10.\s*Local\s*Episodic\s*Effects\s*Possibly\s*Affecting\s*Data\s*Quality\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Signal\s*Obstructions\s*/i ) && ($line !~ /\s*9.3.x\s*/i ) )
          {
            $number_signalobstructions++;
            $signalobstructions{signalobstructions}[$number_signalobstructions] = trim(substr($line,32,length($line)-33));
            $signalobstructions{sectionnumber}[$number_signalobstructions] = trim(substr($line,4,3));
            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Effective\s*Dates\s*/i )        { $signalobstructions{effective_dates}[$number_signalobstructions] = trim(substr($line,32,length($line)-33)); }
                 if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
                 {
                  $signalobstructions{additional_information}[$number_signalobstructions] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $signalobstructions{additional_information}[$number_signalobstructions] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.3.' . $signalobstructions{sectionnumber}[$number_signalobstructions] . '.'; }
                 }
              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 9.3.' . $signalobstructions{sectionnumber}[$number_signalobstructions] . '.'; }
          }
     }

  for($i=1;$i<=$number_signalobstructions;$i++)
   {

      $signalobstructions{additional_information}[$i] =~s/\'/&#39;/g;
      $signalobstructions{additional_information}[$i] =~s/"/&#39;/g;

      if (
         ($signalobstructions{signalobstructions}[$i] ne '(TREES/BUILDLINGS/etc)') or
         ($signalobstructions{effective_dates}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
         ($signalobstructions{additional_information}[$i] ne '(multiple lines)')
         )
      {
      }

     # SECTION NUMBER
     if (($signalobstructions{sectionnumber}[$i] - $i) > 0)
      {
       print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . '' . "\n");
       print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
       $numbererrors++;
      }

     # SIGNAL OBSTRUCTIONS - ORIGIN
     if ( ( length(trim($signalobstructions{signalobstructions}[$i])) == 0 ) || (trim($signalobstructions{signalobstructions}[$i]) eq '(TREES/BUILDLINGS/etc)' ) )
      {
         print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Signal Obstructions : ' . $signalobstructions{signalobstructions}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }


       $error_effective_dates[$i] = '';

       # EFFECTIVE DATES
       if (
          (trim($signalobstructions{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($signalobstructions{effective_dates}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          )
        {
         print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }
       else
        {

          if (trim($signalobstructions{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
           {
            if (
               (substr($signalobstructions{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($signalobstructions{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($signalobstructions{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

           if (
              (substr($signalobstructions{effective_dates}[$i],11,4) < 1980 ) ||
              (substr($signalobstructions{effective_dates}[$i],11,4) > $year)
              )
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($signalobstructions{effective_dates}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($signalobstructions{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($signalobstructions{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($signalobstructions{effective_dates}[$i],11,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : end date ' . substr($signalobstructions{effective_dates}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }


            # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
            if (
               ($error_effective_dates[$i] eq '') &&
               ( substr($signalobstructions{effective_dates}[$i],0,10) gt substr($signalobstructions{effective_dates}[$i],11,11) )
               )
             {
              print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
              print('ERROR : End Date (' . substr($signalobstructions{effective_dates}[$i],11,11) . ') precedes Start Date (' . substr($signalobstructions{effective_dates}[$i],0,10) . ')' . "\n");
              $numbererrors++;
             }



           }


         if (trim($signalobstructions{effective_dates}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          {
            if (
               (substr($signalobstructions{effective_dates}[$i],0,4) < 1980 ) ||
               (substr($signalobstructions{effective_dates}[$i],0,4) > $year)
               )
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : ' . substr($signalobstructions{effective_dates}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($signalobstructions{effective_dates}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 9.3.' . $signalobstructions{sectionnumber}[$i] . ' - "Effective Dates : ' . $signalobstructions{effective_dates}[$i] . "\"\n");
               print('ERROR : start date ' . substr($signalobstructions{effective_dates}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

          }


      }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 10 not found.'; }



  #######################################################################
  # READ SECTION 10.
  #######################################################################
  $number_localepisodiceffects = 0;

  while ( ( $line !~ /^11.\s*On-Site,\s*Point\s*of\s*Contact\s*Agency\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if ( (substr($line,0,32) =~ /\s*Date\s*/i ) && ($line !~ /\s*10.x\s*/i ) )
          {
            $number_localepisodiceffects++;
            $localepisodiceffects{date}[$number_localepisodiceffects] = trim(substr($line,32,length($line)-33));
            $localepisodiceffects{sectionnumber}[$number_localepisodiceffects] = trim(substr($line,3,3));
            while ( (trim($line) ne "") && (!eof(LogFile)) )
              {
                 $line = <LogFile>;

                 if (substr($line,0,32) =~ /\s*Event\s*/i )
                 {
                  $localepisodiceffects{event}[$number_localepisodiceffects] = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $localepisodiceffects{event}[$number_localepisodiceffects] .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 10.' . $localepisodiceffects{sectionnumber}[$number_localepisodiceffects] . '.'; }
                 }

              }
            if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line after subsection No 10.' . $localepisodiceffects{sectionnumber}[$number_localepisodiceffects] . '.'; }
          }
     }


  for($i=1;$i<=$number_localepisodiceffects;$i++)
   {

      $localepisodiceffects{event}[$i] =~s/\'/&#39;/g;
      $localepisodiceffects{event}[$i] =~s/"/&#39;/g;

      if (
          ($localepisodiceffects{date}[$i] ne '(CCYY-MM-DD/CCYY-MM-DD)') or
          ($localepisodiceffects{event}[$i] ne '(TREE CLEARING/CONSTRUCTION/etc)')
         )
      {
      }

       # SECTION NUMBER
       if (($localepisodiceffects{sectionnumber}[$i] - $i) > 0)
        {
         print('Section 10.' . $localepisodiceffects{sectionnumber}[$i] . '' . "\n");
         print('ERROR : wrong section number ... or there is at least a missing section before this one' . "\n");
         $numbererrors++;
        }


       $error_effective_dates[$i] = '';

       # DATE
       if (
          (trim($localepisodiceffects{date}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ ) &&
          (trim($localepisodiceffects{date}[$i]) !~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          )
        {
         print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
         print('ERROR : start and/or end dates are missing. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
         $numbererrors++;
         $error_effective_dates[$i] = 'true';
        }
       else
        {

          if (trim($localepisodiceffects{date}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/ )
           {
            if (
               (substr($localepisodiceffects{date}[$i],0,4) < 1980 ) ||
               (substr($localepisodiceffects{date}[$i],0,4) > $year)
               )
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : ' . substr($localepisodiceffects{date}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

           if (
              (substr($localepisodiceffects{date}[$i],11,4) < 1980 ) ||
              (substr($localepisodiceffects{date}[$i],11,4) > $year)
              )
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : ' . substr($localepisodiceffects{date}[$i],11,4) . ' is a senseless year for the end date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }



            $error_effective_dates[$i] = check_stationlogdate(substr($localepisodiceffects{date}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : start date ' . substr($localepisodiceffects{date}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($localepisodiceffects{date}[$i],11,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : end date ' . substr($localepisodiceffects{date}[$i],11,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }


            # EFFECTIVE DATES (chronology comparison between Date Installed and Date Removed)
            if (
               ($error_effective_dates[$i] eq '') &&
               ( substr($localepisodiceffects{date}[$i],0,10) gt substr($localepisodiceffects{date}[$i],11,11) )
               )
             {
              print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
              print('ERROR : End Date (' . substr($localepisodiceffects{date}[$i],11,11) . ') precedes Start Date (' . substr($localepisodiceffects{date}[$i],0,10) . ')' . "\n");
              $numbererrors++;
             }



           }


         if (trim($localepisodiceffects{date}[$i]) =~ /^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}[\/]{1}CCYY-MM-DD$/ )
          {
            if (
               (substr($localepisodiceffects{date}[$i],0,4) < 1980 ) ||
               (substr($localepisodiceffects{date}[$i],0,4) > $year)
               )
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : ' . substr($localepisodiceffects{date}[$i],0,4) . ' is a senseless year for the start date. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
               $error_effective_dates[$i] = 'true';
             }

            $error_effective_dates[$i] = check_stationlogdate(substr($localepisodiceffects{date}[$i],0,10));
            if($error_effective_dates[$i] ne '')
             {
               print('Section 10.' . $i . ' - "Date : ' . $localepisodiceffects{date}[$i] . "\"\n");
               print('ERROR : start date ' . substr($localepisodiceffects{date}[$i],0,10) . ' -> ' . $error_effective_dates[$i] . '. Use CCYY-MM-DD/CCYY-MM-DD.' . "\n");
               $numbererrors++;
             }

          }


      }




     # EVENT
     if ( ( length(trim($localepisodiceffects{event}[$i])) == 0 ) || (trim($localepisodiceffects{event}[$i]) eq '(TREE CLEARING/CONSTRUCTION/etc)' ) )
      {
         print('Section 10.' . $i . ' - "Event : ' . $localepisodiceffects{event}[$i] . "\"\n");
         print('ERROR : missing input' . "\n");
         $numbererrors++;
      }


   }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 11 not found.'; }



  #######################################################################
  # READ SECTION 11.
  #######################################################################
  $line = <LogFile>;
  while ( ( $line !~ /^12.\s*Responsible\s*Agency\s*/i ) && (!eof(LogFile)) )
     {
       $tmp = substr($line,30,length($line)-31);
       if (substr($line,0,32) =~ /\s*Agency\s*/i )
              {
                  $agency_section11 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Preferred\s*Abbreviation\s*/i ) && (!eof(LogFile)) && (trim($line) ne "") )
                    {
                      if (length($line) >  32) { $agency_section11 .= "\n" . trim(substr($line,32,length($line)-33)); }
                      $line = <LogFile>;
                    }
                  if ( ( (eof(LogFile)) || (trim($line) eq "") ) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Preferred Abbreviation" not found in section No 11.'; }
              }
       if (substr($line,0,32) =~ /\s*Preferred\s*Abbreviation\s*/i )    { $preferredabbreviation_section11 = trim(substr($line,32,length($line)-33));  }
       if ((substr($line,0,32) =~ /\s*Mailing\s*Address\s*/i ) && ($tmp !~ /\s*Mailing\s*Address\s*/i ) )
              {
                  $mailing_address_section11 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Primary\s*Contact\s*/i ) && (!eof(LogFile)) && (trim($line) ne "") )
                    {
                      if (length($line) >  32) { $mailing_address_section11 .= "\n" . trim(substr($line,32,length($line)-33)); }
                      $line = <LogFile>;
                    }
                  if ( ( (eof(LogFile)) || (trim($line) eq "") ) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Primary Contact" not found in section No 11.'; }
              }

       if ((substr($line,0,32) =~ /\s*Primary\s*Contact\s*/i ) && ($tmp !~ /\s*Primary\s*Contact\s*/i ) )
              {
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Secondary\s*Contact\s*/i ) && (!eof(LogFile)) )
                    {

                      if (substr($line,0,32) =~ /\s*Contact\s*Name\s*/i )
                        {
                           $primarycontact_contactname_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(primary\)\s*/i )
                        {
                           $primarycontact_primarytelephone_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(secondary\)\s*/i )
                        {
                           $primarycontact_secondarytelephone_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Fax\s*/i )
                        {
                           $primarycontact_fax_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*E-mail\s*/i )
                        {
                           $primarycontact_email_section11 = trim(substr($line,32,length($line)-33));
                        }
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Secondary Contact" not found in section No 11.'; }

              }
       if ((substr($line,0,32) =~ /\s*Secondary\s*Contact\s*/i ) && ($tmp !~ /\s*Secondary\s*Contact\s*/i ) )
              {
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Additional\s*Information\s*/i ) && (!eof(LogFile)) )
                    {

                      if (substr($line,0,32) =~ /\s*Contact\s*Name\s*/i )
                        {
                           $secondarycontact_contactname_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(primary\)\s*/i )
                        {
                           $secondarycontact_primarytelephone_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(secondary\)\s*/i )
                        {
                           $secondarycontact_secondarytelephone_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Fax\s*/i )
                        {
                           $secondarycontact_fax_section11 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*E-mail\s*/i )
                        {
                           $secondarycontact_email_section11 = trim(substr($line,32,length($line)-33));
                        }

                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Additional Information" not found in section No 11.'; }

              }

       if (substr($line,0,32) =~ /\s*Additional\s*Information\s*/i )
         {
                  $additional_information_section11 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $additional_information_section11 .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line between sections No 11 and No 12.'; }
         }
       $line = <LogFile>;

     }
   $agency_section11 =~s/\'/&#39;/g;
   $agency_section11 =~s/"/&#39;/g;
   $mailing_address_section11 =~s/\'/&#39;/g;
   $mailing_address_section11 =~s/"/&#39;/g;
   $additional_information_section11 =~s/\'/&#39;/g;
   $additional_information_section11 =~s/"/&#39;/g;


   # AGENCY
   if ( ( length(trim($agency_section11)) == 0 ) || (trim($agency_section11) eq '(multiple lines)' ) )
    {
      print('Section 11 - "Agency : ' . $agency_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # PREFERRED ABBREVIATION
   if ( ( length(trim($preferredabbreviation_section11)) == 0 ) || (trim($preferredabbreviation_section11) eq '(A10)' ) )
    {
      print('Section 11 - "Preferred Abbreviation : ' . $preferredabbreviation_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # MAILING ADDRESS
   if ( ( length(trim($mailing_address_section11)) == 0 ) || (trim($mailing_address_section11) eq '(multiple lines)' ) )
    {
      print('Section 11 - "Mailing Address : ' . $mailing_address_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # PRIMARY CONTACT - CONTACT NAME
   if ( length(trim($primarycontact_contactname_section11)) == 0 )
    {
      print('Section 11 - "Primary Contact - Contact Name : ' . $primarycontact_contactname_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # PRIMARY CONTACT - E-MAIL
   if ( length(trim($primarycontact_email_section11)) == 0 )
    {
      print('Section 11 - "Primary Contact - E-mail : ' . $primarycontact_email_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }
   else
    {
      if ($primarycontact_email_section11 !~ /^([\w\-]+(\.[\w\-]+)*)@([\w\-]+(\.[\w\-]+)*)\.(\w+)$/)  # [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
       {
        print('Section 11 - "Primary Contact - E-mail : ' . $primarycontact_email_section11 . "\"\n");
        print('ERROR : invalid address' . "\n");
        $numbererrors++;
       }
    }

   # SECONDARY CONTACT - E-MAIL
   if ( ( length(trim($secondarycontact_email_section11)) == 0 ) && (length(trim($secondarycontact_contactname_section11)) > 0) )
    {
      print('Section 11 - "Secondary Contact - E-mail : ' . $secondarycontact_email_section11 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   if ( ( length(trim($secondarycontact_email_section11)) > 0 ) && (length(trim($secondarycontact_contactname_section11)) > 0) )
    {
      if ($secondarycontact_email_section11 !~ /^([\w\-]+(\.[\w\-]+)*)@([\w\-]+(\.[\w\-]+)*)\.(\w+)$/)  # [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
       {
        print('Section 11 - "Secondary Contact - E-mail : ' . $secondarycontact_email_section11 . "\"\n");
        print('ERROR : invalid address' . "\n");
        $numbererrors++;
       }
    }


  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 12 not found.'; }



  #######################################################################
  # READ SECTION 12.
  #######################################################################
  $line = <LogFile>;
  while ( ( $line !~ /^13.\s*More\s*Information\s*/i ) && (!eof(LogFile)) )
     {
       $tmp = substr($line,30,length($line)-31);
       if (substr($line,0,32) =~ /\s*Agency\s*/i )
              {
                  $agency_section12 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Preferred\s*Abbreviation\s*/i ) && (!eof(LogFile)) && (trim($line) ne "") )
                    {
                      if (length($line) >  32) { $agency_section12 .= "\n" . trim(substr($line,32,length($line)-33)); }
                      $line = <LogFile>;
                    }
                  if ( ( (eof(LogFile)) || (trim($line) eq "") ) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Preferred Abbreviation" not found in section No 12.'; }
              }
       if (substr($line,0,32) =~ /\s*Preferred\s*Abbreviation\s*/i )    { $preferredabbreviation_section12 = trim(substr($line,32,length($line)-33));  }

       if ((substr($line,0,32) =~ /\s*Mailing\s*Address\s*/i ) && ($tmp !~ /\s*Mailing\s*Address\s*/i ) )
              {
                  $mailing_address_section12 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Primary\s*Contact\s*/i ) && (!eof(LogFile)) && (trim($line) ne "") )
                    {
                      if (length($line) >  32) { $mailing_address_section12 .= "\n" . trim(substr($line,32,length($line)-33)); }
                      $line = <LogFile>;
                    }
                  if ( ( (eof(LogFile)) || (trim($line) eq "") ) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Primary Contact" not found in section No 12.'; }
              }

       if ((substr($line,0,32) =~ /\s*Primary\s*Contact\s*/i ) && ($tmp !~ /\s*Primary\s*Contact\s*/i ) )
              {
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Secondary\s*Contact\s*/i ) && (!eof(LogFile)) )
                    {

                      if (substr($line,0,32) =~ /\s*Contact\s*Name\s*/i )
                        {
                           $primarycontact_contactname_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(primary\)\s*/i )
                        {
                           $primarycontact_primarytelephone_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(secondary\)\s*/i )
                        {
                           $primarycontact_secondarytelephone_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Fax\s*/i )
                        {
                           $primarycontact_fax_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*E-mail\s*/i )
                        {
                           $primarycontact_email_section12 = trim(substr($line,32,length($line)-33));
                        }

                      $line = <LogFile>;

                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Secondary Contact" not found in section No 12.'; }
              }

       if ((substr($line,0,32) =~ /\s*Secondary\s*Contact\s*/i ) && ($tmp !~ /\s*Secondary\s*Contact\s*/i ) )
              {
                  $line = <LogFile>;
                  while ( ( $line !~ /\s*Additional\s*Information\s*/i ) && (!eof(LogFile)) )
                    {

                      if (substr($line,0,32) =~ /\s*Contact\s*Name\s*/i )
                        {
                           $secondarycontact_contactname_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(primary\)\s*/i )
                        {
                           $secondarycontact_primarytelephone_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Telephone\s*\(secondary\)\s*/i )
                        {
                           $secondarycontact_secondarytelephone_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*Fax\s*/i )
                        {
                           $secondarycontact_fax_section12 = trim(substr($line,32,length($line)-33));
                        }

                      if (substr($line,0,32) =~ /\s*E-mail\s*/i )
                        {
                           $secondarycontact_email_section12 = trim(substr($line,32,length($line)-33));
                        }

                      $line = <LogFile>;

                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Field "Additional Information" not found in section No 12.'; }
              }

       if ($line =~ /\s*Additional\s*Information\s*/i )
              {
                  $additional_information_section12 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (trim($line) ne "") && (!eof(LogFile)) )
                    {
                      $additional_information_section12 .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                    }
                  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'No empty line between sections No 12 and No 13.'; }
              }
       $line = <LogFile>;

     }
   $agency_section12 =~s/\'/&#39;/g;
   $agency_section12 =~s/"/&#39;/g;
   $mailing_address_section12 =~s/\'/&#39;/g;
   $mailing_address_section12 =~s/"/&#39;/g;
   $additional_information_section12 =~s/\'/&#39;/g;
   $additional_information_section12 =~s/"/&#39;/g;



if ( (length(trim($agency_section12)) > 0) && (trim($agency_section12) ne '(multiple lines)') )
{

   # PREFERRED ABBREVIATION
   if ( ( length(trim($preferredabbreviation_section12)) == 0 ) || (trim($preferredabbreviation_section12) eq '(A10)' ) )
    {
      print('Section 12 - "Preferred Abbreviation : ' . $preferredabbreviation_section12 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # MAILING ADDRESS
   if ( ( length(trim($mailing_address_section12)) == 0 ) || (trim($mailing_address_section12) eq '(multiple lines)' ) )
    {
      print('Section 12 - "Mailing Address : ' . $mailing_address_section12 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # PRIMARY CONTACT - CONTACT NAME
   if ( length(trim($primarycontact_contactname_section12)) == 0 )
    {
      print('Section 12 - "Primary Contact - Contact Name : ' . $primarycontact_contactname_section12 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   # PRIMARY CONTACT - E-MAIL
   if ( length(trim($primarycontact_email_section12)) == 0 )
    {
      print('Section 12 - "Primary Contact - E-mail : ' . $primarycontact_email_section12 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }
   else
    {
      if ($primarycontact_email_section12 !~ /^([\w\-]+(\.[\w\-]+)*)@([\w\-]+(\.[\w\-]+)*)\.(\w+)$/)  # [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
       {
        print('Section 12 - "Primary Contact - E-mail : ' . $primarycontact_email_section12 . "\"\n");
        print('ERROR : invalid address' . "\n");
        $numbererrors++;
       }
    }

   # SECONDARY CONTACT - E-MAIL
   if ( ( length(trim($secondarycontact_email_section12)) == 0 ) && (length(trim($secondarycontact_contactname_section12)) > 0) )
    {
      print('Section 12 - "Secondary Contact - E-mail : ' . $secondarycontact_email_section12 . "\"\n");
      print('ERROR : missing input' . "\n");
      $numbererrors++;
    }

   if ( ( length(trim($secondarycontact_email_section12)) > 0 ) && (length(trim($secondarycontact_contactname_section12)) > 0) )
    {
      if ($secondarycontact_email_section12 !~ /^([\w\-]+(\.[\w\-]+)*)@([\w\-]+(\.[\w\-]+)*)\.(\w+)$/)  # [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}
       {
        print('Section 12 - "Secondary Contact - E-mail : ' . $secondarycontact_email_section12 . "\"\n");
        print('ERROR : invalid address' . "\n");
        $numbererrors++;
       }
    }

 }



  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Title of section No 13 not found.'; }


  #######################################################################
  # READ SECTION 13.(until Antenna Graphics with Dimensions)
  #######################################################################
  while ( ( $line !~ /\s*Antenna\s*Graphics\s*with\s*Dimensions\s*/i ) && (!eof(LogFile)) )
     {
       $line = <LogFile>;
       if (substr($line,0,32) =~ /\s*Primary\s*Data\s*Center\s*/i )        { $primary_data_center = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Secondary\s*Data\s*Center\s*/i )      { $secondary_data_center = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*URL\s*for\s*More\s*Information\s*/i ) { $url_for_more_information = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Site\s*Map\s*/i )                     { $site_map = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Site\s*Diagram\s*/i )                 { $site_diagram = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Horizon\s*Mask\s*/i )                 { $horizon_mask = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Monument\s*Description\s*/i )         { $monument_description_MI = trim(substr($line,32,length($line)-33)); }
       if (substr($line,0,32) =~ /\s*Site\s*Pictures\s*/i )                { $site_pictures = trim(substr($line,32,length($line)-33)); }


       if ($line =~ /\s*Additional\s*Information\s*/i )
              {
                  $additional_information_section13 = trim(substr($line,32,length($line)-33));
                  $line = <LogFile>;
                  while ( (( $line !~ /\s*Antenna\s*Graphics\s*with\s*Dimensions\s*/i ) && (trim($line) ne "")) && (!eof(LogFile)) )
                    {
                      $additional_information_section13 .= "\n" . trim(substr($line,32,length($line)-33));
                      $line = <LogFile>;
                   }
                 if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 13 - line "Antenna Graphics with Dimensions" not found'; }

              }
     }


   $additional_information_section13 =~s/\'/&#39;/g;
   $additional_information_section13 =~s/"/&#39;/g;


   # PRIMARY DATA CENTRE
   if ( length(trim($primary_data_center)) == 0 )
    {
      print('Section 13 - "Primary Data Center : ' . $primary_data_center . "\"\n");
      if ($strict eq 'D') { print('WARNING : missing input (recommended).' . "\n"); }
      else { print('ERROR : missing input.' . "\n"); }
      $numbererrors++;
    }

   # SECONDARY DATA CENTRE
   if ( length(trim($secondary_data_center)) == 0 )
    {
      print('Section 13 - "Secondary Data Center : ' . $secondary_data_center . "\"\n");
      print('WARNING : missing input (recommended).' . "\n");
      $numbererrors++;
    }

  if ( (eof(LogFile)) && ($encounteredproblem eq '') ) { $encounteredproblem = 'Section 13 - line "Antenna Graphics with Dimensions" not found'; }


  #######################################################################
  # READ "Antenna Graphics with Dimensions" (in the section 13.)
  #######################################################################
  $antenna_graphics_with_dimensions = "";
  while (!eof(LogFile) )
     {
       $line = <LogFile>;
       $antenna_graphics_with_dimensions .= $line;
     }

  $antenna_graphics_with_dimensions =~s/\'/&#39;/g;
  $antenna_graphics_with_dimensions =~s/"/&#39;/g;


  #######################################################################

  close(LogFile);

  if ($encounteredproblem ne "") { print("$encounteredproblem\n"); }

  if($numbererrors == 0) { print('No warning or error.' . "\n"); }

  print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' . "\n");

 }
