Skip to content

Instantly share code, notes, and snippets.

@fils
Last active February 11, 2020 02:14
Show Gist options
  • Save fils/dc015ea0681169349294177d6b0ea5d4 to your computer and use it in GitHub Desktop.
Save fils/dc015ea0681169349294177d6b0ea5d4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"github.com/fhs/go-netcdf/netcdf"
)
func main() {
fileset()
}
func fileset() {
start := time.Now()
s := start.AddDate(0, 0, -3)
e := start.AddDate(0, 0, -1)
for rd := rangeDate(s, e); ; {
date := rd()
if date.IsZero() {
break
}
d := fmt.Sprint(date.Format("20060102"))
for i := 0; i <= 23; i++ {
t := fmt.Sprintf("%02d", i)
fmt.Printf("https://storage.cloud.google.com/national-water-model/nwm.%s/analysis_assim/nwm.t%sz.analysis_assim.channel_rt.tm00.conus.nc\n", d, t)
}
}
}
func rangeDate(start, end time.Time) func() time.Time {
y, m, d := start.Date()
start = time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
y, m, d = end.Date()
end = time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
return func() time.Time {
if start.After(end) {
return time.Time{}
}
date := start
start = start.AddDate(0, 0, 1)
return date
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment