[Rodbcext-commits] r17 - pkg/geoclimate/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 30 10:00:12 CEST 2012


Author: jaunario
Date: 2012-03-30 10:00:12 +0200 (Fri, 30 Mar 2012)
New Revision: 17

Modified:
   pkg/geoclimate/R/nasa.r
Log:
Improve defective download detection

Modified: pkg/geoclimate/R/nasa.r
===================================================================
--- pkg/geoclimate/R/nasa.r	2012-03-20 06:04:59 UTC (rev 16)
+++ pkg/geoclimate/R/nasa.r	2012-03-30 08:00:12 UTC (rev 17)
@@ -32,10 +32,15 @@
 			dlines <- readLines(fname)
 		}
 		
-		if (length(dlines)>20){
-			stline <- grep(paste(format(stdate,"%Y"),format(as.numeric(format(stdate,"%j")),width=3)), dlines)
-			endline <- grep(paste(format(endate,"%Y"),format(as.numeric(format(endate,"%j")),width=3)), dlines)
-
+		# Check download integrity
+		stline <- grep(paste(format(stdate,"%Y"),format(as.numeric(format(stdate,"%j")),width=3)), dlines)
+		endline <- grep(paste(format(endate,"%Y"),format(as.numeric(format(endate,"%j")),width=3)), dlines)
+		if (length(stline)!=1|length(endline)!=1){
+			show.message("Incomplete or No data found on file. If file ", basename(fname), " is on disk, remove the file then rerun this program.")
+			
+		} else if(length(unlist(strsplit(gsub("[[:space:]]+"," ",dlines[endline]), " ")))!=10){
+			show.message("Incomplete download detected. If file ", basename(fname), " is on disk, remove the file then rerun this program.")
+		} else {
 			writeLines(dlines, fname)
 			alt <- as.numeric(unlist(strsplit(dlines[grep("Elevation", dlines)],"="))[2])
 			dlines <- dlines[stline:endline]
@@ -57,3 +62,4 @@
 	}
 	return(result)
 }
+ get.nasa(-177.5,64.5,st="2009-1-1", en="2012-2-29", rm.existing=FALSE)
\ No newline at end of file



More information about the Rodbcext-commits mailing list