-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREAD_CTD.R
71 lines (43 loc) · 1.32 KB
/
READ_CTD.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
read_CTD <- function ( filenc_core ){
##################################################
#### DATA MODE
##################################################
DATA_MODE=unlist(strsplit(ncvar_get(filenc_core,"DATA_MODE"),split=""))
DATA_MODE_CTD=DATA_MODE[1]
##################################################
#### Get the Best CTD
##################################################
if ( DATA_MODE_CTD == "R" ) {
PSAL=ncvar_get(filenc_core,"PSAL")
TEMP=ncvar_get(filenc_core,"TEMP")
PRES=ncvar_get(filenc_core,"PRES")
} else {
PSAL=ncvar_get(filenc_core,"PSAL_ADJUSTED")
TEMP=ncvar_get(filenc_core,"TEMP_ADJUSTED")
PRES=ncvar_get(filenc_core,"PRES_ADJUSTED")
}
#### CTD is always the 1st profile of the nc
if (filenc_core$dim$N_PROF$len == 1 ) {
PSAL_CTD=PSAL
TEMP_CTD=TEMP
PRES_CTD=PRES
} else {
if( all(is.na(PSAL) & length(PSAL)==2)) {
PSAL_CTD=NA
TEMP_CTD=NA
PRES_CTD=NA
} else {
PSAL_CTD=PSAL[,1]
TEMP_CTD=TEMP[,1]
PRES_CTD=PRES[,1]
if( all(is.na(PSAL[,1])) & all(!is.na(PSAL[,2])) ) { # Get the discrete CTD profiles to adjust doxy
PSAL_CTD=PSAL[,2]
TEMP_CTD=TEMP[,2]
PRES_CTD=PRES[,2]
}
}
}
result=(list(PRES=PRES_CTD,PSAL=PSAL_CTD,TEMP=TEMP_CTD))
#result=(list(PRES=PRES,PSAL=PSAL,TEMP=TEMP))
return(result)
}