-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.R
95 lines (76 loc) · 1.8 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/Rscript
# This script is intended to download daily
# GPS raw data for a requested year.
# Input variables
# year -- requested year
# dir -- catalog with download data
# 7zip -- 7-zip command to extract files
year <- "2011"
myDir <- "src/"
# cmd <- paste0("7za e -o", myDir, " -y ")
cmd <- paste0("7za e -o", myDir, "brdc", " -y ")
# Example link: ftp://cddis.gsfc.nasa.gov/gps/data/daily/2002/175/02n/brdc1750.02n.Z
# Example link 2: ftp://cddis.gsfc.nasa.gov//pub/gps/data/daily/2000/brdc/brdc0010.00n.Z
# This function will download daily GPS data
# for given day in a year and will store it
# on disk as a data frame.
# Input parameters: year, day
# Output: file on disk, data frame
downloadDay <- function(year,day)
{
short_year <- substr(year, 3, 4)
filename <- paste0(
"brdc",
formatC(day, width=3, flag="0"),
"0.",
short_year,
"n.Z"
)
link <- paste0(
"ftp://cddis.gsfc.nasa.gov//pub/gps/data/daily/",
year,
"/brdc/",
filename
)
if (!file.exists(myDir))
{
dir.create(myDir)
}
fullpath <- paste0(myDir,filename)
#download.file(link, fullpath)
cmd <- paste0(
cmd,
fullpath
)
print(cmd)
system(cmd)
}
downloadData <- function()
{
for (i in 1:365)
downloadDay(year, i)
}
# Temporary parameters
file <- "src/brdc0010.11n"
prn <- 4
extractData <- function(file,prn)
{
rnxData <- readLines(file)
nLines <- length(rnxData)
print("nLInes: ", nLines)
# Skipping a header
for (i in 1:100)
if (grepl("END OF HEADER", rnxData[i])) break
cLine <- i + 1
# Reading each PRN
while (cLine <= nLines)
{
# Establishing connection
buffer <- rnxData[cLine]
con <- textConnection(buffer)
# Formatted RINEX reading (Fortran)
}
rnxData
}
downloadData()
# d <- extractData(file,prn)