parsing the date and time from the igc file
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sun, 22 Jan 2012 20:46:02 +0100
changeset 12 84b0f3ca474a
parent 11 d927333c8ffe
child 13 c5ee81217f70
parsing the date and time from the igc file
igc.cc
igc.h
main.cc
mainwindow.cc
--- a/igc.cc	Sun Jan 22 17:35:21 2012 +0100
+++ b/igc.cc	Sun Jan 22 20:46:02 2012 +0100
@@ -6,16 +6,25 @@
 	char c;
 	in >> c;
 	switch (c) {
-	    case 'A': theAuthor = in.readLine(); break;
+	    case 'A': 
+		if (device_.isEmpty()) device_ = in.readLine(); 
+		break;
 	    case 'H': {
-		      QString line  = in.readLine();
-		      QString key   = line.section(':', 0, 0);
-		      QString value = line.section(':', 1, 1).simplified();
-		      if (key.startsWith("FPLT")) thePilot = value;
-		      if (key.startsWith("FGTY")) theGlider = value;
-		      }
-		      break;
-	    case 'B': fixes << in.readLine(); break;
+		QString line  = in.readLine();
+		QString key   = line.section(':', 0, 0);
+		QString value = line.section(':', 1, 1).simplified();
+
+		if (key.startsWith("FPLT")) pilot_ = value;
+		else if (key.startsWith("FGTY")) glider_ = value;
+		else if (key.startsWith("FDTE")) {
+		    QString s = line.mid(4);
+		    if (s.length() == 6) 
+			s.insert(4, "20"); // FIXME: current year?
+		    date_ = QDate::fromString(s, "ddMMyyyy");
+		}
+	    }
+	    break;
+	    case 'B': fixes_ << in.readLine(); break;
 	}
     }
 }
@@ -23,12 +32,16 @@
 Fix::Fix(const QString &s)
 {
     int pos = 0;
-    theTime = s.mid(pos, 6); pos += 6;
-    gps.lat = s.mid(pos, 8); pos += 8;
-    gps.lon = s.mid(pos, 9); pos += 9;
-    valid = s.mid(pos, 1); pos += 1;
-    theAlt.press = s.mid(pos, 5).toInt(); pos += 5;
-    theAlt.gps = s.mid(pos, 5).toInt(); pos += 5;
+
+    time_ = QTime::fromString(s.mid(pos, 6), "hhmmss"); 
+    pos += 6;	
+
+    gps_.lat = s.mid(pos, 8); pos += 8;	// DDMMmmm[NS]
+    gps_.lon = s.mid(pos, 9); pos += 9;	// DDDMMmmm[EW]
 
-    qDebug() << theAlt.press << " | " << theAlt.gps;
+    fix3d_ = s.mid(pos, 1) == "A"; 
+    pos += 1;
+
+    alt_.baro = s.mid(pos, 5).toInt(); pos += 5;
+    alt_.gps = s.mid(pos, 5).toInt(); pos += 5;
 }
--- a/igc.h	Sun Jan 22 17:35:21 2012 +0100
+++ b/igc.h	Sun Jan 22 20:46:02 2012 +0100
@@ -7,15 +7,16 @@
   public: 
     Fix(const QString&);
   private:
-    QString theTime, valid;
+    QTime time_;
+    bool fix3d_;
     struct {
 	QString lon;
 	QString lat;
-    } gps;
+    } gps_;
     struct {
-	int press;
+	int baro;
 	int gps;
-    } theAlt;
+    } alt_;
 };
 
 typedef QList<Fix> Fixes;
@@ -23,12 +24,13 @@
 class IGC {
   public:
     void read(QTextStream&);
-    QString author() const { return theAuthor; }
-    QString pilot() const { return thePilot; }
+    QString device() const { return device_; }
+    QString pilot() const { return pilot_; }
+    QDate date() const { return date_; }
   private:
-    QString theAuthor, thePilot, theGlider;
-    QStringList points;
-    Fixes fixes;
+    QString device_, pilot_, glider_;
+    QDate date_;
+    Fixes fixes_;
 
 };
 #endif
--- a/main.cc	Sun Jan 22 17:35:21 2012 +0100
+++ b/main.cc	Sun Jan 22 20:46:02 2012 +0100
@@ -1,4 +1,4 @@
-#include <QApplication>
+#include "pch.h"
 #include "mainwindow.h"
 
 
--- a/mainwindow.cc	Sun Jan 22 17:35:21 2012 +0100
+++ b/mainwindow.cc	Sun Jan 22 20:46:02 2012 +0100
@@ -24,6 +24,9 @@
 	    "flights", tr("IGC files (*.igc);; All files (*)"));
     if (fileName.isEmpty()) return;
 
+    if(currentFile.isOpen()) 
+	currentFile.close();
+
     currentFile.setFileName(fileName);
 
     if (!currentFile.open(QFile::ReadOnly)) {
@@ -39,4 +42,8 @@
 
     igc.read(input);
 
+    qDebug() << igc.device();
+    qDebug() << igc.pilot();
+    qDebug() << igc.date();
+
 }