GetBands <- function(Product) { if(!any(Product == GetProducts())) stop("Product entered does not match any available products; see ?GetProducts.") getbands.xml <- paste(' ', Product, ' ', sep = "") header.fields <- c(Accept = "text/xml", Accept = "multipart/*", 'Content-Type' = "text/xml; charset=utf-8", SOAPAction = "") reader <- basicTextGatherer() header <- basicTextGatherer() curlPerform(url = paste0(daacmodis, wsdl_loc), httpheader = header.fields, postfields = getbands.xml, writefunction = reader$update, verbose = FALSE) # Check the server is not down by insepcting the XML response for internal server error message. if(grepl("Internal Server Error", reader$value())){ stop("Web service failure: the ORNL DAAC server seems to be down, please try again later. The online subsetting tool may indicate when the server is up and running again.") } xmlres <- xmlRoot(xmlTreeParse(reader$value())) bandsres <- xmlSApply(xmlres[[1]], function(x) xmlSApply(x, function(x) xmlSApply(x,xmlValue))) if(colnames(bandsres) == "Fault"){ if(length(bandsres['faultstring.text', ][[1]]) == 0){ stop("Downloading from the web service is currently not working. Please try again later.") } stop(bandsres['faultstring.text', ]) } else{ return(as.vector(bandsres)) } }