Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 93 lines (80 sloc) 2.207 kb
bb35c65 @sramsay ...
authored
1 /*
2 * tide.go
3 *
4 * This file is part of wu. It contains functions related to
28d8020 @sramsay Minor correction to comment block.
authored
5 * the -tides switch (high and low tide data).
bb35c65 @sramsay ...
authored
6 *
7 * Written and maintained by Stephen Ramsay <sramsay.unl@gmail.com>
8 * and Anthony Starks.
9 *
0473fa6 @sramsay Reformatted tides output.
authored
10 * Last Modified: Wed May 30 10:14:20 CDT 2012
bb35c65 @sramsay ...
authored
11 *
12 * Copyright © 2010-2012 by Stephen Ramsay and Anthony Starks.
13 *
14 * wu is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3, or (at your option)
17 * any later version.
18 *
19 * wu is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22 * License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with wu; see the file COPYING. If not see
26 * <http://www.gnu.org/licenses/>.
27 */
28
29 package main
30
243e322 @sramsay Finished tidal data (without trapping for non-coastal areas).
authored
31 import (
3bed8a0 @sramsay Reformatting.
authored
32 "fmt"
33 "os"
34 "strconv"
0473fa6 @sramsay Reformatted tides output.
authored
35 "time"
243e322 @sramsay Finished tidal data (without trapping for non-coastal areas).
authored
36 )
bb35c65 @sramsay ...
authored
37
38 type TideConditions struct {
3bed8a0 @sramsay Reformatting.
authored
39 Tide Tide
bb35c65 @sramsay ...
authored
40 }
41
42 type Tide struct {
3bed8a0 @sramsay Reformatting.
authored
43 Tideinfo []Tideinfo
44 Tidesummary []Tidesummary
bb35c65 @sramsay ...
authored
45 }
46
47 type Tideinfo struct {
3bed8a0 @sramsay Reformatting.
authored
48 Tidesite string
bb35c65 @sramsay ...
authored
49 }
50
51 type Tidesummary struct {
3bed8a0 @sramsay Reformatting.
authored
52 Date Date // Defined in wu.go
53 Data Data
bb35c65 @sramsay ...
authored
54 }
55
56 type Data struct {
3bed8a0 @sramsay Reformatting.
authored
57 Height string
58 Type string
bb35c65 @sramsay ...
authored
59 }
60
0473fa6 @sramsay Reformatted tides output.
authored
61 // printTides prints the tidal data for given station to standard out
fe3dc6e @sramsay Fixed bug #27.
authored
62 func PrintTides(obs *TideConditions, stationID string) {
3bed8a0 @sramsay Reformatting.
authored
63 tide := obs.Tide
64 info := tide.Tideinfo
65 summary := tide.Tidesummary
239513b @sramsay Added "not available."
authored
66
3bed8a0 @sramsay Reformatting.
authored
67 if len(summary) == 0 {
68 fmt.Println("No tidal data available.")
69 os.Exit(0)
70 }
239513b @sramsay Added "not available."
authored
71
3bed8a0 @sramsay Reformatting.
authored
72 fmt.Printf("Tidal data for %s\n", info[0].Tidesite)
243e322 @sramsay Finished tidal data (without trapping for non-coastal areas).
authored
73
0473fa6 @sramsay Reformatted tides output.
authored
74 var date_string string
75 var prev_date string
76
380d7cb @sramsay Rewrote tides routine to be more sane (and helpful!).
authored
77 for _, s := range summary {
0473fa6 @sramsay Reformatted tides output.
authored
78 month, _ := strconv.Atoi(s.Date.Mon)
380d7cb @sramsay Rewrote tides routine to be more sane (and helpful!).
authored
79 hour, _ := strconv.Atoi(s.Date.Hour)
0473fa6 @sramsay Reformatted tides output.
authored
80 prev_date = date_string
81 date_string = time.Month(month).String() + " " + s.Date.Mday + ", " + s.Date.Year + ":"
82 if date_string != prev_date {
83 fmt.Println(date_string)
84 }
380d7cb @sramsay Rewrote tides routine to be more sane (and helpful!).
authored
85 if hour < 13 {
0473fa6 @sramsay Reformatted tides output.
authored
86 fmt.Printf(" %s at %d:%s AM\n", s.Data.Type, hour, s.Date.Min)
380d7cb @sramsay Rewrote tides routine to be more sane (and helpful!).
authored
87 } else {
88 hour = hour - 12
0473fa6 @sramsay Reformatted tides output.
authored
89 fmt.Printf(" %s at %d:%s PM\n", s.Data.Type, hour, s.Date.Min)
fe3dc6e @sramsay Fixed bug #27.
authored
90 }
3bed8a0 @sramsay Reformatting.
authored
91 }
bb35c65 @sramsay ...
authored
92 }
Something went wrong with that request. Please try again.