! bn230_cdf.sub2
! benchmark to test abstract variable netCDF input and output
! requires version 2.30 or later
! 6/92

! V5 *sh* 7/99 added /CLOBBER

cancel region
canc var/all
cancel data/all

! define a realistic time series grid
define axis/t="1-jan-1902":"1-jan-2010":1/unit=day tcentury
define grid/like=abstract/t=tcentury gcentury
let tlong = t[g=gcentury]

let i1 = i
let j1 = j
let k1 = k
let l1 = l[g=gcentury]
let l2 = l
let ij = i+j
let ik = i+k
let il = i+l1
let jk = j+k
let jl = j+l1
let kl = k+l1
let ijk = i+j+k
let ikl = i+k+l1
let ijl = i+j+l1
let jkl = j+k+l1
let ijkl = i+j+k+l1
let ijk2 = i+j+k
let ikl2 = i+k+l1
let ijl2 = i+j+l1
let jkl2 = j+k+l1
let iavejkl = ijkl[i=@ave]
let ijavekl = ijkl[j=@ave]
let ijkavel = ijkl[k=@ave]
let ijklave = ijkl[l=@ave]

! a bunch of basic geometries
! 1d
list/format=cdf/keep_axnames/i=1:10/clobber/file=test_abs.cdf i1   ! not /APPEND - must be new
list/format=cdf/keep_axnames/j=1:20/append/file=test_abs.cdf j1
list/format=cdf/keep_axnames/k=1:100/append/file=test_abs.cdf k1
list/format=cdf/keep_axnames/l=1:10/append/file=test_abs.cdf l1           ! record axis
list/format=cdf/keep_axnames/l=1:10/append/file=test_abs.cdf l2           ! rigid axis

! 2D
list/format=cdf/keep_axnames/i=1:10/j=1:20/append/file=test_abs.cdf ij
list/format=cdf/keep_axnames/i=1:10/k=1:100/append/file=test_abs.cdf ik
list/format=cdf/keep_axnames/i=1:10/l=5:10/append/file=test_abs.cdf il
list/format=cdf/keep_axnames/k=1:100/j=1:20/append/file=test_abs.cdf jk

!3D
set region/i=1:10/j=1:20/k=1:100/l=4:8
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijk
list/format=cdf/keep_axnames/append/file=test_abs.cdf ikl
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijl
list/format=cdf/keep_axnames/append/file=test_abs.cdf jkl

!4D
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijkl

! extend along time axis and write sub-regions
! (note: this may leave undefined regions in other variables)
list/format=cdf/keep_axnames/append/file=test_abs.cdf/i=1:5 /j=1:5 /l=11:12 ijl
list/format=cdf/keep_axnames/append/file=test_abs.cdf/i=6:10/j=1:5 /l=11:12 ijl
list/format=cdf/keep_axnames/append/file=test_abs.cdf/i=1:5 /j=6:10/l=11:12 ijl
list/format=cdf/keep_axnames/append/file=test_abs.cdf/i=6:10/j=6:10/l=11:12 ijl

! rewrite a sub-region in the middle of the data
list/format=cdf/keep_axnames/append/file=test_abs.cdf/i=6:8/j=6:8/l=8:10/k=3:5 ijkl

! check documentation of transforms
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijk2[i=@ave]
list/format=cdf/keep_axnames/append/file=test_abs.cdf ikl2[i=@ave,k=@sbx:3]
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijl2[i=@ave,j=@ave]
list/format=cdf/keep_axnames/append/file=test_abs.cdf jkl2[k=@ave,l=@ave]
list/format=cdf/keep_axnames/append/file=test_abs.cdf iavejkl
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijavekl
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijkavel
list/format=cdf/keep_axnames/append/file=test_abs.cdf ijklave

! look at what we've created - time axis should be regular
set data/format=cdf test_abs
show data/full
cancel variable ijkl
show grid ijkl
cancel data test_abs

! make the time axis irregular by leaving out l=13
list/format=cdf/keep_axnames/l=14:16/append/file=test_abs.cdf l1
set data/format=cdf test_abs
show data/full
show grid ijkl

