From 970ae216cc58d7ece69ba0479d6ee7ec8cd5be69 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 9 Dec 2020 08:29:20 +0100 Subject: [PATCH 1/2] [ADIF Parser] Modifications done to the ADIF parser to speed up ADIF files containing several thousand QSOs. --- application/libraries/Adif_parser.php | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/application/libraries/Adif_parser.php b/application/libraries/Adif_parser.php index fbf99f1b..e8ba9f60 100644 --- a/application/libraries/Adif_parser.php +++ b/application/libraries/Adif_parser.php @@ -19,8 +19,9 @@ class ADIF_Parser { var $data; //the adif data + var $datasplit; // one entry is one QSO in the array + var $currentarray = 0; // current place in the array var $i; //the iterator - var $current_line; //stores information about the current qso var $headers = array(); public function initialize() //this function locates the @@ -97,7 +98,8 @@ class ADIF_Parser } } - + + $this->datasplit = preg_split("//i", substr($this->data, $this->i)); $this->i++; }; @@ -177,22 +179,21 @@ class ADIF_Parser return $return; } - //finds the next record in the file public function get_record() { - if($this->i >= strlen($this->data)) - { - return array(); //return nothing - }; - $end = stripos($this->data, "", $this->i); - if($end == false) //is this the end? - { - return array(); //return nothing - }; - $record = substr($this->data, $this->i, $end-$this->i); - $this->i = $end+5; - return $this->record_to_array($record); //process and return output + // Are we at the end of the array containing the QSOs? + if($this->currentarray >= count($this->datasplit)) { + return array(); //return nothing + } else { + // Is this a valid QSO? + if (stristr($this->datasplit[$this->currentarray],"record_to_array($this->datasplit[$this->currentarray++]); //process and return output + } + else { + return array(); + } + } } public function get_header($key) From 41ff9749da199ce28c63b901914b2c09d6e33ac3 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 11 Dec 2020 23:52:11 +0100 Subject: [PATCH 2/2] [ADIF Parser] Placed split line correct --- application/libraries/Adif_parser.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/libraries/Adif_parser.php b/application/libraries/Adif_parser.php index e8ba9f60..956a47ec 100644 --- a/application/libraries/Adif_parser.php +++ b/application/libraries/Adif_parser.php @@ -99,7 +99,6 @@ class ADIF_Parser } } - $this->datasplit = preg_split("//i", substr($this->data, $this->i)); $this->i++; }; @@ -110,6 +109,8 @@ class ADIF_Parser echo "Error: ADIF File Does Not Contain Any QSOs"; return 0; }; + + $this->datasplit = preg_split("//i", substr($this->data, $this->i)); return 1; }