Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
radolan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonny Schäfer
radolan
Commits
a5fc4be5
Commit
a5fc4be5
authored
8 years ago
by
Jonny Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
Add NewComposites function
parent
a3ef3796
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
radolan.go
+37
-1
37 additions, 1 deletion
radolan.go
with
37 additions
and
1 deletion
radolan.go
+
37
−
1
View file @
a5fc4be5
...
@@ -19,10 +19,13 @@
...
@@ -19,10 +19,13 @@
package
radolan
package
radolan
import
(
import
(
"archive/tar"
"bufio"
"bufio"
"compress/gzip"
"fmt"
"fmt"
"io"
"io"
"math"
"math"
"sort"
"time"
"time"
)
)
...
@@ -81,7 +84,7 @@ type Composite struct {
...
@@ -81,7 +84,7 @@ type Composite struct {
offy
float64
// vertical projection offset
offy
float64
// vertical projection offset
}
}
// NewComposite reads from rd and parses the composite.
// NewComposite reads
binary data
from rd and parses the composite.
func
NewComposite
(
rd
io
.
Reader
)
(
comp
*
Composite
,
err
error
)
{
func
NewComposite
(
rd
io
.
Reader
)
(
comp
*
Composite
,
err
error
)
{
reader
:=
bufio
.
NewReader
(
rd
)
reader
:=
bufio
.
NewReader
(
rd
)
comp
=
&
Composite
{}
comp
=
&
Composite
{}
...
@@ -101,6 +104,39 @@ func NewComposite(rd io.Reader) (comp *Composite, err error) {
...
@@ -101,6 +104,39 @@ func NewComposite(rd io.Reader) (comp *Composite, err error) {
return
return
}
}
// NewComposites reads tar gz data from rd and returns the parsed composites sorted by
// ForecastTime in ascending order.
func
NewComposites
(
rd
io
.
Reader
)
([]
*
Composite
,
error
)
{
gzipReader
,
err
:=
gzip
.
NewReader
(
rd
)
if
err
!=
nil
{
return
nil
,
err
}
defer
gzipReader
.
Close
()
tarReader
:=
tar
.
NewReader
(
gzipReader
)
var
cs
[]
*
Composite
for
{
_
,
err
:=
tarReader
.
Next
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
return
nil
,
err
}
c
,
err
:=
NewComposite
(
tarReader
)
if
err
!=
nil
{
return
nil
,
err
}
cs
=
append
(
cs
,
c
)
}
// sort composites in chronological order
sort
.
Slice
(
cs
,
func
(
i
,
j
int
)
bool
{
return
cs
[
i
]
.
ForecastTime
.
Before
(
cs
[
j
]
.
ForecastTime
)
})
return
cs
,
nil
}
// NewDummy creates a blank dummy composite with the given product label and dimensions. It can
// NewDummy creates a blank dummy composite with the given product label and dimensions. It can
// be used for generic coordinate translation.
// be used for generic coordinate translation.
func
NewDummy
(
product
string
,
dx
,
dy
int
)
(
comp
*
Composite
)
{
func
NewDummy
(
product
string
,
dx
,
dy
int
)
(
comp
*
Composite
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment