-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathodf_check
128 lines (123 loc) · 3.33 KB
/
odf_check
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
####check ODF metadata before exporting to NC####
#' Check ODF metadata
#'
#' Check that an ODF object has all the metadata required to build a complete netCDF file
#'
#' @param obj an odf object (oce::read.odf())
#' @param print TRUE or FALSE, TRUE will cause errors to be displayed at command
#' line, FALSE will sink errors into text document
#'
#' @return will print any issues with metadata to command line, if nothing
#' prints then all metadata is intact
#' @export
#'
#' @examples
odf_check <- function(obj, print = TRUE){
if (print == FALSE){
name <- gsub(obj[['filename']], pattern = ".ODF", replacement = "")
sink(file = paste0(name, '_metadata_check.txt'))
}
if (is.null(obj[['longitude']])){
print('Missing Longitude Value!')
}
if (is.na(obj[['longitude']])){
print('Missing Longitude Value!')
}
if (is.null(obj[['latitude']])){
print('Missing Latitude Value!')
}
if (is.na(obj[['latitude']])){
print('Missing Latitude Value!')
}
if (is.null(obj[['type']])){
print('Missing type value!')
}
if (is.na(obj[['type']])){
print('Missing type value!')
}
if (is.null(obj[['model']])){
print('Missing model value!')
}
if (is.na(obj[['model']])){
print('Missing model value!')
}
if (is.null(obj[['samplingInterval']])){
print('Missing SamplingInterval value!')
}
if (is.na(obj[['samplingInterval']])){
print('Missing SamplingInterval value!')
}
if (is.null(obj[['countryInstituteCode']])){
print('Missing CountryInstituteCode value!')
}
if (obj[['countryInstituteCode']] == 0){
print('Missing CountryInstituteCode value!')
}
if (is.na(obj[['countryInstituteCode']])){
print('Missing CountryInstituteCode value!')
}
if(is.null(obj[['cruiseNumber']])){
print('Missing cruiseNumber value!')
}
if(is.na(obj[['cruiseNumber']])){
print('Missing cruiseNumber value!')
}
if (is.null(obj[['station']])){
print('Missing station value!')
}
if (is.na(obj[['station']])){
print('Missing station value!')
}
if (is.null(obj[['serialNumber']])){
print('Missing serialNumber value!')
}
if (is.na(obj[['serialNumber']])){
print('Missing serialNumber value!')
}
if (is.null(obj[['cruise']])){
print('Missing cruise value')
}
if (is.na(obj[['cruise']])){
print('Missing cruise value')
}
if (is.null(obj[['sounding']])){
print('Missing sounding value!')
}
if (is.na(obj[['sounding']])){
print('Missing sounding value!')
}
if (is.null(obj[['scientist']])){
print('Missing scientist value!')
}
if (is.na(obj[['scientist']])){
print('Missing scientist value!')
}
if (is.null(obj[['waterDepth']])){
print('Missing waterDepth value!')
}
if (is.na(obj[['waterDepth']])){
print('Missing waterDepth value!')
}
if (is.null(obj[['depthMin']])){
print('Missing depthMin value')
}
if (is.na(obj[['depthMin']])){
print('Missing depthMin value')
}
if (is.null(obj[['depthMax']])){
print('Missing depthMax value')
}
if (is.na(obj[['depthMax']])){
print('Missing depthMax value')
}
if (is.null(obj[['institute']])){
print('Missing institute value')
}else{
if (length(grep(obj[['institute']], pattern = 'DFO')) == 0){
print(paste("institute value is '", obj[['institute']], "' should be 'DFO BIO'"))
}
}
if(print == FALSE){
sink(NULL)
}
}