|
|
|
# Examples
|
|
|
|
|
|
|
|
## Index
|
|
|
|
|
|
|
|
1. [ArrayToNc](#1-arraytonc)
|
|
|
|
1. It uses synthetic data to show how to save a data array with its dimension variables (lat, lon, time) and the corresponding attributes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 1. ArrayToNc
|
|
|
|
|
|
|
|
* **1-1**
|
|
|
|
|
|
|
|
```r
|
|
|
|
library(easyNCDF)
|
|
|
|
|
|
|
|
# Create synthetic data
|
|
|
|
data <- array(1:200, dim = c(lat = 10, lon = 10, time = 2))
|
|
|
|
lats <- array(1:10, dim = c(lat = 10))
|
|
|
|
lons <- array(-10:-1, dim = c(lon = 10))
|
|
|
|
times <- array(c(as.POSIXct("2010-01-01"), as.POSIXct("2010-02-01")), dim = c(time = 2))
|
|
|
|
|
|
|
|
# Create metadata for each variable
|
|
|
|
meta <- list(
|
|
|
|
tas = list(long_name = "near-surface temperature", units = "K"),
|
|
|
|
lat = list(long_name = "latitude", units = "degrees_north"),
|
|
|
|
lon = list(long_name = "longitude", units = "degrees_east"),
|
|
|
|
time = list(calendar = "standard"))
|
|
|
|
|
|
|
|
# Attach metadata to data
|
|
|
|
attr(data, 'variables') <- meta[1]
|
|
|
|
attr(lats, 'variables') <- meta[2]
|
|
|
|
attr(lons, 'variables') <- meta[3]
|
|
|
|
attr(times, 'variables') <- meta[4]
|
|
|
|
|
|
|
|
# Save to .nc file
|
|
|
|
ArrayToNc(list(tas = data, lat = lats, lon = lons, time = times), "example1.nc")
|
|
|
|
``` |
|
|
|
\ No newline at end of file |