getPart.R 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Author: Matteo Mattiuzzi, [email protected]
  2. # Date : February 2012
  3. ################################
  4. # getPart() takes as argument ONLY a defineName() or a getProduct() result, or basicaly a vector with named "nodes"
  5. ################################
  6. getPart <- function(x, what = c('YYYY', 'DDD', 'DATE', 'SENSOR', 'PF1', 'PF2'
  7. , 'PF3', 'PLATFORM', 'TILE', 'TILEV', 'TILEH'
  8. , 'C', 'CCC', 'PRODUCT', 'FORMAT', 'COMPRESSION'
  9. , 'DATE1DATE2', 'PROCESSINGDATE', 'REGION'
  10. , 'TIME'))
  11. {
  12. if (missing(x)){
  13. return(cat("Available 'placeholders' are:",what,"\n",sep=" "))
  14. }
  15. what <- match.arg(what)
  16. switch(what,
  17. YYYY = substring(x$DATE,2,5), # works with AYYYYDDD input # TODO a scanning function to detect teh first numeric value in x$DATE
  18. DDD = substring(x$DATE,6,8), # works with AYYYYDDD input
  19. DATE = gsub(transDate(begin=substring(x$DATE,2,8))$begin,pattern="-",replacement="."), # works with AYYYYDDD input
  20. SENSOR = x$SENSOR,
  21. PF1 = x$PF1,
  22. PF2 = x$PF2,
  23. PF3 = x$PF3,
  24. PLATFORM = x$PLATFORM,
  25. TILE = x$TILE,
  26. C = as.numeric(x$CCC),
  27. CCC = x$CCC,
  28. PRODUCT = x$PRODUCT,
  29. FORMAT = x$FORMAT,
  30. COMPRESSION = x$COMPRESSION,
  31. DATE1DATE2 = x$DATE1DATE2,
  32. PROCESSINGDATE = x$PROCESSINGDATE,
  33. REGION = "EuropeAfrica", # the only supported for now!
  34. TIME = x$TIME,
  35. TILEV = if (sign(x$TILEV)==-1) {paste("s",sprintf("%03d",abs(x$TILEV)))} else {paste("n",sprintf("%03d",x$TILEV))},
  36. TILEH = x$TILEH
  37. )
  38. }