checkIntegrity.R 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. checkIntegrity <- function(x, opts = NULL, ...) {
  2. ## if options have not been passed down, create them from '...'
  3. if (is.null(opts))
  4. opts <- combineOptions(...)
  5. opts$stubbornness <- stubborn(opts$stubbornness)
  6. iw <- getOption("warn")
  7. options(warn=-1)
  8. on.exit(options(warn=iw))
  9. if(!opts$gdalOk)
  10. {
  11. warning("Something wrong with your GDAL installation, see '?MODISoptions' for more details")
  12. } else
  13. {
  14. cmd <- paste0(opts$gdalPath,"gdalinfo ")
  15. out <- rep(NA,length(x))
  16. for (i in seq_along(x))
  17. {
  18. if (basename(x[i])=="NA" | is.na(basename(x[i])))
  19. {
  20. out[i] <- NA
  21. } else
  22. {
  23. if (dirname(x[i])==".")
  24. {
  25. x[i] <- paste0(genString(x=x[i],remote=FALSE,...)$localPath, basename(x[i]))
  26. }
  27. if (!file.exists(x[i]))
  28. {
  29. out[i] <- NA
  30. } else
  31. {
  32. try(a <- system(paste0(cmd,correctPath(x[i],isFile=TRUE)), intern=TRUE), silent=TRUE)
  33. if(length(grep(a,pattern="gdalinfo failed")==1) | length(a)==0)
  34. {
  35. out[i] <- FALSE
  36. } else
  37. {
  38. out[i] <- TRUE
  39. }
  40. }
  41. }
  42. }
  43. return(out)
  44. }
  45. }