annotate cmd/soundingresults/main.go @ 977:4a2ca0e20006

Fixed build error. Copied file to the wrong place and said 'go build' to another wrong place. Argh.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 18 Oct 2018 17:30:53 +0200
parents 4e90daa57086
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 package main
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 import (
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 "bufio"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 "database/sql"
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
6 "encoding/hex"
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 "flag"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 "fmt"
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
9 "io"
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 "log"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 "os"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 "path/filepath"
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
13 "runtime"
612
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
14 "sort"
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 "strings"
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
16 "sync"
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 "time"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 "github.com/jackc/pgx"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 "github.com/jackc/pgx/stdlib"
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 )
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 var (
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
24 dump = flag.Bool("dump", true, "dump SQL insert statements")
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 insecure = flag.Bool("insecure", false, "skip SSL verification")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 dbhost = flag.String("dbhost", "localhost", "database host")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 dbport = flag.Uint("dbport", 5432, "database port")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 dbname = flag.String("dbname", "gemma", "database user")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 dbuser = flag.String("dbuser", "scott", "database user")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 dbpassword = flag.String("dbpw", "tiger", "database password")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 dbssl = flag.String("dbssl", "prefer", "database SSL mode")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 )
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 func run(fn func(*sql.DB) error) error {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 // To ease SSL config ride a bit on parsing.
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 cc, err := pgx.ParseConnectionString("sslmode=" + *dbssl)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 if err != nil {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 return err
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 // Do the rest manually to allow whitespace in user/password.
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 cc.Host = *dbhost
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 cc.Port = uint16(*dbport)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 cc.User = *dbuser
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 cc.Password = *dbpassword
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 cc.Database = *dbname
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 db := stdlib.OpenDB(cc)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 defer db.Close()
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 return fn(db)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54
617
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
55 // TODO: This should come from the depth_references table.
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
56 var knownDepthReferences = []string{
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
57 "ADR", "ETRS", "FZP", "GLW", "HBO",
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
58 "HDC", "HNW", "HSW", "IGN", "KP",
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
59 "LDC", "LNW", "NAP", "NGM", "POT",
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
60 "PUL", "RN", "TAW", "WGS", "ZPG",
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
61 }
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
62
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
63 func isKnownDepthReference(ref string) bool {
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
64 ref = strings.ToUpper(ref)
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
65 for _, r := range knownDepthReferences {
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
66 if r == ref {
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
67 return true
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
68 }
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
69 }
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
70 return false
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
71 }
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
72
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 type meta struct {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 date time.Time
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 name string
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 depthReference string
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 func substituteName(fname, name string) string {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80 dir := filepath.Dir(fname)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 info := filepath.Join(dir, "INFO.txt")
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 f, err := os.Open(info)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 if err != nil {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 log.Printf("warn: %v\n", err)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 return name
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87 defer f.Close()
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 s := bufio.NewScanner(f)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 for search := strings.ToLower(name); s.Scan(); {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 line := strings.TrimSpace(s.Text())
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 if line == "" || strings.HasPrefix(line, "#") {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 continue
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 if parts := strings.SplitN(line, "=", 2); len(parts) == 2 &&
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 strings.TrimSpace(strings.ToLower(parts[0])) == search {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99 return strings.TrimSpace(parts[1])
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 if err := s.Err(); err != nil {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 log.Printf("error: %v\n", err)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107 return name
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
110 func parseFilename(fname string) (*meta, error) {
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 base := filepath.Base(fname)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113
602
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
114 compressed := strings.ToLower(filepath.Ext(base))
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
115 for _, ext := range []string{".gz", ".bz2"} {
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
116 if ext == compressed {
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
117 base = base[:len(base)-len(ext)]
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
118 break
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
119 }
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
120 }
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
121
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
122 // Cut .txt
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
123 base = base[:len(base)-len(filepath.Ext(base))]
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
124
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
125 if !strings.HasSuffix(strings.ToUpper(base), "_WGS84") {
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
126 return nil, fmt.Errorf("%s is not in WGS84", base)
602
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
127 }
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
128
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
129 base = base[:len(base)-len("_WGS84")]
10f898bbe50f Sounding results: Accept if XYZ files are compressed with GZIP or BZIP2
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 600
diff changeset
130
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 idx := strings.IndexRune(base, '_')
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
132 if idx == -1 {
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
133 return nil, fmt.Errorf("%s has no date", base)
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
134 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
135
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
136 datePart := base[:idx]
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
137
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
138 date, err := time.Parse("20060102", datePart)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
139 if err != nil {
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
140 return nil, fmt.Errorf("error %s: %v\n", datePart, err)
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
141 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
142
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
143 rest := base[idx+1:]
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
144
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
145 if idx = strings.LastIndex(rest, "_"); idx == -1 {
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
146 return nil, fmt.Errorf("%s has no depth reference", base)
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
147 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
148
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
149 depthReference := rest[idx+1:]
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
150
617
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
151 if !isKnownDepthReference(depthReference) {
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
152 return nil, fmt.Errorf(
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
153 "%s is not a known depth reference", depthReference)
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
154 }
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
155
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
156 rest = rest[:idx]
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
157
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
158 if !strings.HasSuffix(strings.ToUpper(rest), "_MB") {
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
159 return nil, fmt.Errorf("%s is not in WGS84", base)
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
160 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
161
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
162 name := rest[:len(rest)-len("_MB")]
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
163
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
164 name = substituteName(fname, name)
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
165
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
166 return &meta{
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
167 name: name,
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
168 depthReference: depthReference,
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
169 date: date,
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
170 }, nil
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
171 }
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
172
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
173 type result struct {
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
174 m *meta
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
175 points points3d
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
176 wkb string
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
177 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
178
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
179 func processor(fnames <-chan string, results chan<- result, wg *sync.WaitGroup) {
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
180 defer wg.Done()
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
181
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
182 for fname := range fnames {
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
183 log.Printf("Processing %s\n", fname)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
184 m, err := parseFilename(fname)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
185 if err != nil {
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
186 log.Printf("error: %v\n", err)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
187 continue
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
188 }
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
189 _ = m
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
190 points, err := parseXYZ(fname)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
191 if err != nil {
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
192 log.Printf("error: %v\n", err)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
193 continue
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
194 }
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
195 log.Printf("Number of points: %d\n", len(points))
607
21f1f03a8a39 Sounding results: Added simple WKB encoder for points3d.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 606
diff changeset
196
21f1f03a8a39 Sounding results: Added simple WKB encoder for points3d.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 606
diff changeset
197 wkb := points.asWKB()
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
198 log.Printf("WKB size %.2f MB\n", float64(len(wkb))/(1024*1024))
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
199
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
200 results <- result{m, points, wkb}
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
201 }
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
202 }
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
203
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
204 func quote(s string) string {
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
205 return "'" + strings.Replace(s, "'", "'''", -1) + "'"
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
206 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
207
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
208 func main() {
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
209 flag.Parse()
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
210
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
211 var wg sync.WaitGroup
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
212
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
213 fnames := make(chan string)
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
214 results := make(chan result)
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
215 done := make(chan struct{})
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
216
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
217 handler := func(result) {}
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
218 flush := func() {}
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
219
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
220 if *dump {
612
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
221 var results []result
617
4e90daa57086 Sounding results: Reject unknown depth references earlier before loading the XYZ files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 613
diff changeset
222 handler = func(r result) { results = append(results, r) }
612
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
223 flush = func() {
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
224 sort.Slice(results, func(i, j int) bool {
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
225 if a, b := results[i].m.name, results[j].m.name; a != b {
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
226 return a < b
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
227 }
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
228 return results[i].m.date.Before(results[j].m.date)
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
229 })
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
230 out := bufio.NewWriter(os.Stdout)
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
231 fmt.Fprintln(out, "BEGIN;")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
232 for i := range results {
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
233 r := &results[i]
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
234 fmt.Fprintln(out, "INSERT INTO waterway.sounding_results (")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
235 fmt.Fprintln(out, " bottleneck_id,")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
236 fmt.Fprintln(out, " date_info,")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
237 fmt.Fprintln(out, " depth_reference,")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
238 fmt.Fprintln(out, " point_cloud")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
239 fmt.Fprintln(out, ") VALUES (")
613
99cd44f19e86 Sounding results: Fetch bottleneck_id from bottleneck table by objnam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 612
diff changeset
240 fmt.Fprintf(out,
99cd44f19e86 Sounding results: Fetch bottleneck_id from bottleneck table by objnam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 612
diff changeset
241 " (SELECT bottleneck_id from waterway.bottlenecks where objnam = %s),\n",
99cd44f19e86 Sounding results: Fetch bottleneck_id from bottleneck table by objnam.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 612
diff changeset
242 quote(r.m.name))
612
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
243 fmt.Fprintf(out, " '%s'::date,\n", r.m.date.Format("2006-01-02"))
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
244 fmt.Fprintf(out, " %s,\n", quote(r.m.depthReference))
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
245 fmt.Fprintf(out, " '")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
246 io.Copy(hex.NewEncoder(out), strings.NewReader(r.wkb))
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
247 fmt.Fprintln(out, "'")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
248 fmt.Fprintln(out, ");")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
249 }
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
250 fmt.Fprintln(out, "COMMIT;")
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
251 out.Flush()
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
252 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
253 } else {
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
254 // TODO: Implement database stuff.
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
255 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
256
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
257 fin := make(chan struct{})
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
258
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
259 go func() {
612
d127856e689d Sounding results: Sort the data sets by name and date to make the output deterministic.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 611
diff changeset
260 defer func() { flush(); close(fin) }()
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
261 for {
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
262 select {
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
263 case <-done:
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
264 return
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
265 case r := <-results:
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
266 handler(r)
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
267 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
268 }
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
269 }()
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
270
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
271 for i, n := 0, runtime.NumCPU(); i < n; i++ {
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
272 wg.Add(1)
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
273 go processor(fnames, results, &wg)
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
274 }
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
275
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
276 for _, fname := range flag.Args() {
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
277 fnames <- fname
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
278 }
603
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
279
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
280 close(fnames)
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
281
3d33c53db1e3 Sounding results: Read point data from xyz files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 602
diff changeset
282 wg.Wait()
611
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
283
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
284 close(done)
effd22c0ae5a Sounding result: Write simple SQL insert dumper. Not deterministic, yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
285 <-fin
600
30eb8c823ff7 Started with importing the sounding results. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
286 }