Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script to get MCD14ML MODIS data
- library(RCurl)
- library(dplyr)
- # fetch_MCD14ML() downloads all of the zipped data files for the
- # MODIS MCD14ML data product
- #
- # args:
- # dir: the name of a directory to store the zip files (string)
- # overwrite: should existing data be overrwitten? (logical)
- #
- # returns:
- # none, but downloads all of the zip files in "dir"
- #
- # example:
- # fetch_MCD14ML('mcd_test')
- fetch_MCD14ML <- function(dir, overwrite = FALSE) {
- if (!dir.exists(dir)) {
- dir.create(dir, recursive = TRUE)
- }
- ftp_prefix <- 'ftp://fire:burnt@fuoco.geog.umd.edu/modis/C6/mcd14ml/'
- # make vector of filenames on ftp server
- files <- getURL(ftp_prefix, dirlistonly = TRUE) %>%
- strsplit(split = '\n') %>%
- unlist()
- # make ftp paths to each file
- to_download <- lapply(files, FUN = function(x) paste0(ftp_prefix, x)) %>%
- unlist()
- # download each
- destination_files <- file.path(dir, files)
- pb <- txtProgressBar(max = length(destination_files))
- for (i in seq_along(destination_files)) {
- if (!file.exists(destination_files[i]) | overwrite) {
- download.file(to_download[i], destination_files[i])
- }
- setTxtProgressBar(pb, i)
- }
- close(pb)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement