-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch.r
executable file
·67 lines (59 loc) · 1.93 KB
/
batch.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Make a directory with all files, or, figure out how to cut up the
#original input file. The latter is probably the best way to go.
# -> Take the original file and edit into a good, easy, standard shape.
#
#From each of the files we need the city name.
#
#Set working dir to output.
#
#Grab next 3 columns of input file. Get the name.
#
#Run the proc.latlon on the columns ( o = proc.latlon)
#
#Write the results to cur dir (write(o,'city name')
#
#We are done.
#
#
# batch script
cat("Set your working directory.!!\n")
dat = read.csv(file.choose(),header=TRUE)
# Data sets are 4 columns wide and separated by an empty column.
# The first column header is the city name and other info.
# The next three are Latitude, Longitude and volume.
# They can be in any order.
cat("Set working dir now\n")
input = scan()
# first columns will be 1,6,11,16 = 1 + 5*i
len = length(names(dat))/5
for(i in 0:(len-1)){
j = 1 + (i*5)
work.set = dat[,j:(j+3)]
file.name = names(work.set)[1]
xls.name = paste(file.name,".xls",sep='')
cat("Starting ", file.name, " .\n")
if(!file.exists(xls.name)){
lat.col = grep("^latitude",names(work.set),ignore.case=TRUE)
lon.col = grep("^longitude",names(work.set),ignore.case=TRUE)
vol.col = grep("^volume",names(work.set),ignore.case=TRUE)
stid.col = 1
my.ps = cbind(work.set[stid.col],work.set[lat.col],work.set[lon.col],
work.set[vol.col])
# remove NAs
my.ps = my.ps[!is.na(my.ps[,2]),]
names(my.ps) = c("stid","latitude","longitude","vol")
# rows variable is just used for testing
rows=nrow(my.ps)
if (rows > 40){
rows = 40
}
o = proc.latlon(my.ps[1:rows,])
cat("writing ", file.name ,"...\n")
write.table(o$vol.dist.mat,xls.name,row.names=FALSE)
save(o,file=paste(file.name,".rda",sep=''))
# write the file to an output
print(head(my.ps))
} else {
cat("Skipping ", file.name , ". Delete it from working dir to run again.\n")
}
}