-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReplicatingVessels.R
81 lines (54 loc) · 3.31 KB
/
ReplicatingVessels.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
# replicate files from a vessel
# JUST GIVEN AS A FAKE EXAMPLE, USE WITH CARE
namefiles <- c( "_gshape_cpue_per_stk_on_nodes_quarter", "_freq_possible_metiers_quarter", "_gscale_cpue_per_stk_on_nodes_quarter",
"_possible_metiers_quarter", "_cpue_per_stk_on_nodes_quarter")
appname <- "testexample"
foldername <- paste("DISPLACE_input_", appname, sep="")
vesselid_to_replicate <- "DNK00001"
vesselids <- 2:100
for (namefile in namefiles) {
for (Q in 1:4){
er <- try(
dd <- read.table(paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",vesselid_to_replicate,namefile, Q, ".dat", sep=""), header=TRUE)
)
if(class(er)=="try-error") stop("not such a vessel id in the original data")
for (vesselid in vesselids) {
if (vesselid < 10) prefix <- "DNK00" else prefix <- "DNK0"
write.table(dd, file=paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",prefix,vesselid,namefile,Q,".dat", sep=""),col.names=TRUE, row.names=FALSE, sep=" ", quote=FALSE)
}
}
}
for (namefile in c("vesselsspe_betas_semester", "vesselsspe_percent_tacs_per_pop_semester")){
for (S in 1:2){
dd <- read.table(paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",namefile,S,".dat", sep=""), header=TRUE)
for (vesselid in vesselids){
obj <- dd[dd[,1]==vesselid_to_replicate, ]
if (vesselid < 10) prefix <- "DNK00" else prefix <- "DNK0"
obj[,1] <- paste(prefix,vesselid, sep='')
dd <- rbind.data.frame (dd, obj)
}
write.table(dd, file=paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",namefile, S,".dat", sep=""),col.names=TRUE, row.names=FALSE, sep=" ", quote=FALSE)
}
}
for (namefile in c("vesselsspe_fgrounds_quarter", "vesselsspe_freq_fgrounds_quarter", "vesselsspe_harbours_quarter", "vesselsspe_freq_harbours_quarter")){
for (Q in 1:4){
dd <- read.table(paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",namefile,Q,".dat", sep=""), header=TRUE)
for (vesselid in vesselids){
obj <- dd[dd[,1]==vesselid_to_replicate, ]
if (vesselid < 10) prefix <- "DNK00" else prefix <- "DNK0"
obj[,1] <- paste(prefix,vesselid, sep='')
dd <- rbind.data.frame (dd, obj)
}
write.table(dd, file=paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\",namefile,Q,".dat", sep=""),col.names=TRUE, row.names=FALSE, sep=" ", quote=FALSE)
}
}
for (Q in 1:4){
dd <- read.table(paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\","vesselsspe_features_quarter",Q,".dat", sep=""), sep="|", header=FALSE)
for (vesselid in vesselids){
obj <- dd[dd[,1]==vesselid_to_replicate, ]
if (vesselid < 10) prefix <- "DNK00" else prefix <- "DNK0"
obj[,1] <- paste(prefix,vesselid, sep='')
dd <- rbind.data.frame (dd, obj)
}
write.table(dd, file=paste("C:\\Users\\fbas\\Documents\\GitHub\\",foldername,"\\vesselsspe_",appname,"\\","vesselsspe_features_quarter",Q,".dat", sep=""), sep="|", col.names=FALSE, row.names=FALSE, quote=FALSE)
}