GetProducts.R 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. GetProducts <-
  2. function()
  3. {
  4. getproducts.xml <- paste('
  5. <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mod="https://modis.ornl.gov/MODIS_soapservice">
  6. <soapenv:Header/>
  7. <soapenv:Body>
  8. <mod:getproducts soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  9. </soapenv:Body>
  10. </soapenv:Envelope>',
  11. sep = "")
  12. header.fields <- c(Accept = "text/xml",
  13. Accept = "multipart/*",
  14. 'Content-Type' = "text/xml; charset=utf-8",
  15. SOAPAction = "")
  16. reader <- basicTextGatherer()
  17. header <- basicTextGatherer()
  18. curlPerform(url = paste0(daacmodis, wsdl_loc),
  19. httpheader = header.fields,
  20. postfields = getproducts.xml,
  21. writefunction = reader$update,
  22. verbose = FALSE)
  23. # Check the server is not down by insepcting the XML response for internal server error message.
  24. if(grepl("Internal Server Error", reader$value())){
  25. stop("Web service failure: the ORNL DAAC server seems to be down, please try again later.
  26. The online subsetting tool (https://daac.ornl.gov/cgi-bin/MODIS/GLBVIZ_1_Glb/modis_subset_order_global_col5.pl)
  27. will indicate when the server is up and running again.")
  28. }
  29. xmlres <- xmlRoot(xmlTreeParse(reader$value()))
  30. productsres <- xmlSApply(xmlres[[1]],
  31. function(x) xmlSApply(x,
  32. function(x) xmlSApply(x,xmlValue)))
  33. if(colnames(productsres) == "Fault"){
  34. if(length(productsres['faultstring.text', ][[1]]) == 0){
  35. stop("Downloading from the web service is currently not working. Please try again later.")
  36. }
  37. stop(productsres['faultstring.text', ])
  38. } else{
  39. return(as.vector(productsres))
  40. }
  41. }