From 8daceb4b160112d1caada503e3b6b543ed9cb47a Mon Sep 17 00:00:00 2001
From: Since <ax20yhum@cip.cs.fau.de>
Date: Wed, 14 Sep 2016 14:36:50 +0200
Subject: [PATCH] Add Interval field and parsing

---
 header.go      | 14 ++++++++++++++
 header_test.go |  8 ++++++++
 radolan.go     |  1 +
 3 files changed, 23 insertions(+)

diff --git a/header.go b/header.go
index 35d7574..e4308c9 100644
--- a/header.go
+++ b/header.go
@@ -76,6 +76,20 @@ func (c *Composite) parseHeader(reader *bufio.Reader) error {
 		c.ForecastTime = c.CaptureTime.Add(time.Duration(min) * time.Minute)
 	}
 
+	// Parse Interval - Example "INT   5" or "INT1008"
+	if intr, ok := section["INT"]; ok {
+		min := 0
+		if _, err := fmt.Sscanf(intr, "%d", &min); err != nil {
+			return newError("parseHeader", "could not parse interval: "+err.Error())
+		}
+
+		c.Interval = time.Duration(min) * time.Minute
+		switch c.Product {
+		case "W1", "W2", "W3", "W4":
+			c.Interval *= 10
+		}
+	}
+
 	// Parse Dimensions - Example: "GP 450x 450" or "BG460460" or "GP 1500x1400"
 	dim := section["GP"]
 	if bg, ok := section["BG"]; ok {
diff --git a/header_test.go b/header_test.go
index 5cf2576..1dd9575 100644
--- a/header_test.go
+++ b/header_test.go
@@ -16,6 +16,7 @@ type headerTestcase struct {
 	expProduct      string
 	expCaptureTime  time.Time
 	expForecastTime time.Time
+	expInterval     time.Duration
 	expDx           int
 	expDy           int
 	expDataLength   int
@@ -65,6 +66,7 @@ func TestParseHeaderFZ(t *testing.T) {
 	ht.expProduct = "FZ"
 	ht.expCaptureTime, err1 = time.Parse(time.RFC1123, "Thu, 28 Jul 2016 23:05:00 CEST")
 	ht.expForecastTime, err2 = time.Parse(time.RFC1123, "Fri, 29 Jul 2016 00:45:00 CEST")
+	ht.expInterval = 5 * time.Minute
 	ht.expDx = 450
 	ht.expDy = 450
 	ht.expDataLength = 405160 - 154 // BY - header_etx_length
@@ -106,6 +108,12 @@ func testParseHeader(t *testing.T, ht *headerTestcase) {
 			dummy.ForecastTime.String(), ht.expForecastTime.String())
 	}
 
+	// Interval
+	if dummy.Interval != ht.expInterval {
+		t.Errorf("%s.parseHeader(): Interval: %#v; expected: %#v", ht.expProduct,
+			dummy.Interval.String(), ht.expInterval.String())
+	}
+
 	// Dx Dy
 	if dummy.Dx != ht.expDx || dummy.Dy != ht.expDy {
 		t.Errorf("%s.parseHeader(): Dx: %d Dy: %d; expected Dx: %d Dy: %d", ht.expProduct,
diff --git a/radolan.go b/radolan.go
index 1dde0e7..d889777 100644
--- a/radolan.go
+++ b/radolan.go
@@ -62,6 +62,7 @@ type Composite struct {
 
 	CaptureTime  time.Time
 	ForecastTime time.Time
+	Interval     time.Duration
 
 	Data [][]RVP6 // rvp-6 data for each point [y][x]
 
-- 
GitLab