extractDate: Extract dates from (MODIS) files

Description Usage Arguments Value Author(s) Examples

Description

This function helps to extract dates in a vector of files

Usage

1
extractDate(files,pos1=10,pos2=16,asDate=FALSE,format='%Y%j')

Arguments

files

vector of filenames where from extract the dates. Can include also the filepath!

pos1

Start position of date in the filename. You have to count, sorry!

pos2

End position of date in the filename. You have to count, sorry!

asDate

Logical, default is FALSE. If TRUE the result is converted to a Date object

format

Used only if asDate=TRUE, MODIS dates are normally formatted as "%Y%j" (Year and julian day) See: as.Date for modifications.

Value

Vector with character, if asDate=FALSE or vector of "Date"'s if TRUE, extracted from filenames

Author(s)

Matteo Mattiuzzi

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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")

## End(Not run)

aubreyd/modis4rwrfhydro documentation built on May 10, 2019, 2:13 p.m.