Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active February 16, 2016 05:10
Show Gist options
  • Save mdsumner/dbd702480f103e99bc9c to your computer and use it in GitHub Desktop.
Save mdsumner/dbd702480f103e99bc9c to your computer and use it in GitHub Desktop.
## NOTE: as is this code downloads 3 files, 22Mb in total
## files to compare
files <- c("A2015283.L3m_DAY_CHL_chlor_a_4km.nc", "A2015284.L3m_DAY_CHL_chlor_a_4km.nc", "A2015285.L3m_DAY_CHL_chlor_a_4km.nc")
baseu <- "http://oceandata.sci.gsfc.nasa.gov/cgi/getfile"
## download the files
for (i in seq_along(files)) {
if (!file.exists(files[i])) {
download.file(file.path(baseu, files[i]), files[i], mode = "wb")
}
}
library(ncdf4)
## open each file and print "lat" range
for (i in seq_along(files)) {
nc <- nc_open(files[i])
lat <- ncvar_get(nc, "lat")
print(sprintf("%s latitude range: %f,%f", files[i], min(lat), max(lat)))
nc_close(nc)
}
# [1] "A2015283.L3m_DAY_CHL_chlor_a_4km.nc latitude range: -89.979179,89.979164"
# [1] "A2015284.L3m_DAY_CHL_chlor_a_4km.nc latitude range: -269.979187,-90.020836"
# [1] "A2015285.L3m_DAY_CHL_chlor_a_4km.nc latitude range: -89.979179,89.979164"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment