library(oce)
# Example 1: made-up data
d <- new("oce")
d <- oceSetData(d, "S", c(30, 31))
d <- oceSetData(d, "T", c(10, 11))
dictText <- "S,salinity,,
T,temperature,degree*C,ITS-90"
dictionary <- read.csv(text = dictText, header = FALSE)
oceRename(d, dictionary)
#
# Example 2: a CIOOS NetCDF file. Note that this file
# is downloaded and removed at the end; in practice,
# it is likely that the file might be retained locally.
if (requireNamespace("curl")) {
file <- tempfile(fileext = ".nc") # removed later
server <- "https://cioosatlantic.ca/erddap/files"
program <- "bio_atlantic_zone_monitoring_program_ctd"
subprogram <- "Bedford%20Basin%20Monitoring%20Program"
year <- 2023
cast <- 1
url <- sprintf(
"%s/%s/%s/%s/CTD_BCD%s667_%03d_1_DN.ODF.nc",
server, program, subprogram, year, year, cast
)
t <- try(curl::curl_download(url, file), silent = TRUE)
if (!inherits(t, "try-error")) {
d <- read.netcdf(file)
summary(d)
dd <- oceRename(d, "ioos")
summary(dd)
} else {
message("Cannot connect to ", url)
}
unlink(file)
}
Run the code above in your browser using DataLab