MODIS (version 1.1.7)

extractDate: Extract Dates from (MODIS) Files

Description

This function helps to extract dates from a vector of files.

Usage

extractDate(files, pos1, pos2, asDate = FALSE, format = "%Y%j")

Arguments

files

A character vector of filenames from which to extract dates. Alternatively, a Raster* with date information in its layer names.

pos1, pos2

Start and end of date string in files as integer. If missing, positions are tried to be retrieved from a look-up table provided that 'files' comply with the MODIS standard naming convention.

asDate

logical. If TRUE, the result is converted to a Date object.

format

character, date format. Used only if asDate = TRUE. Defaults to MODIS date style (i.e., "%Y%j" for year and julian day). See strptime for modifications.

Value

A list with the following entries: 'inputLayerDates', 'pos1', 'pos2', 'asDate' and, optionally, 'format'. If asDate = FALSE, 'inputLayerDates' are represented as character, else as Date.

Examples

Run this code
# NOT RUN {
# example on HDF files
files <- c("MOD13Q1.A2010209.h18v03.005.2010239071130.hdf",
           "MOD13Q1.A2010225.h18v03.005.2010254043849.hdf")
extractDate(files)
extractDate(files, asDate = TRUE)

# on any other file 
files <- c("Myfile_20010101.XXX", "Myfile_20010115.XXX", "Myfile_20010204.XXX")
extractDate(files, pos1 = 8, pos2 = 15)
extractDate(files, pos1 = 8, pos2 = 15, asDate = TRUE, format = "%Y%m%d")
 
# }

Run the code above in your browser using DataLab