! bn_long_grid_names.jnl
! test longer grid names (16 --> 64 chars)
! tests taken from other bn scripts but with longer grid names

! read onto a 2D grid
DEFINE AXIS/X=1:3:1 xez1
DEFINE GRID/X=XEZ1/Y=EZ ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890

FILE/VAR="X1,X2"/COLUMNS=6/GRID=ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 EZ.DAT
SHOW DATA/FULL
LIST X1
SHOW DATA
CAN DATA/ALL

define axis/x=2:20:2 xeven
define axis/x=1:19:2 xodd
define axis/y=2:20:2 yeven
define axis/y=1:19:2 yodd
define axis/z=2:20:2 zeven
define axis/z=1:19:2 zodd
define axis/t=2:20:2/t0="1-jan-1980"/unit=days teven
define axis/t=1:19:2/t0="1-jan-1980"/unit=days todd

define grid/x=xeven/y=yeven/z=zeven/t=teven even

define grid/x=xodd/y=yodd/z=zodd/t=todd g00abcdefghijklmnopqrstuvwxyz1234567890

LET veven = 1000*i[g=even] + 100*j[g=even] + 10*k[g=even] + l[g=even]

LET v1234 = veven[g=g00abcdefghijklmnopqrstuvwxyz1234567890]

SET REGION/X=4.01:8.99/Y=4.01:8.99/Z=4.01:8.99/T=4.01:8.99

list veven
list v1234
stat veven

! first all from one memory variable
load/x=1:11/y=1:11/z=1:11/t=1:11 veven
stat v1234[g=even]-veven, v1234

go bn_reset
! regrid_transforms
use gtsa056_1
use gtsa056_2
set mode diag

define axis/t=15-jan-1982:15-mar-1984:120/unit=hour tax5day
define axis/x=120e:60w:10/unit=degrees xax10
define grid/like=u/t=tax5day g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day
define grid/like=u/x=xax10/z=w/t=tax5day g5_10g00abcdefghijklmnopqrstuvwxyz1234567890

set reg/x=130w:125w/y=0:1.5/z=0:15/t=21-JAN-1982:24-jan-1982
!set reg/i=101:105/j=41:42/k=1:2/l=3:4

use gtsa056_1    	!kob 4/99

LIST temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@ave]
LIST temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890,gx=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@ave]

LIST temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890,gt=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@asn]

! T axis
use gtsa056_2	!kob  4/99
set region/x=180W/y=0/z=5/t=21-JAN-1982:13-JUN-1983
load temp[i=50:51,j=45:56,k=1:2,l=1:172]  ! preload to save time
plot temp
plot/over temp[g=u]
plot/over temp[g=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day]
plot/over temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890]
plot/over temp[g=u@ave]
plot/over temp[g=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day@ave]
plot/over temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@ave]
plot/over temp[g=u@asn]
plot/over temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@asn]
plot/over temp[g=u,gt=u@ave]
plot/over temp[g=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day,gt=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day@ave]
plot/over temp[g=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890,gt=g5_10g00abcdefghijklmnopqrstuvwxyz1234567890@ave]
plot/over temp[g=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day,gt=g5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5dayg5day@asn]  ! invalid interpretation of data


set mode/last diag

go bn_reset
! regrid_to_user

use coads_climatology
use levitus_climatology

! define test objects
let a = sst[d=coads_climatology] + 1
let b = sst + 1		! data set unspecified
DEFINE AXIS/Y=20s:20n:.5/units=degrees yax
DEFINE GRID/like=sst[d=coads_climatology]/y=yax gg12345678901234567890

! reference data
list/x=158e:161e/y=6s:4s temp[d=2,k=1]

! basic regrid (implicit grid -- sst and temp geometries are mismatched)
list/x=160e/y=5s temp[d=2,k=1,g=a[d=1]]
show grid

! per axis regrid
! 5/01 note: changed from y=0 yo y=5s to accomodate Y-truncated
! levitus_climatology.cdf
list/x=160e/y=5s temp[d=2,k=1,gx=a[d=1],gy=yax]
list/x=160e/y=5s temp[d=2,k=1,gy=yax,gx=a[d=1]]
show grid

! combined full grid and per-axis
list/x=160e/y=5s temp[d=2,k=1,g=gg12345678901234567890,gx=a[d=1]]
list/x=160e/y=5s temp[d=2,k=1,gx=a[d=1],g=gg12345678901234567890]
show grid

! pseudo-variable access
list/i=1:4 i[g=a]		! a is previously loaded
let c = a
list/i=1:4 i[g=c]		! c is not previously loaded
let d = c
list/i=1:4 x[gx=d]

! DEFINE GRID based on a user-defined variable
let e = d
DEFINE GRID/LIKE=e/x=temp[d=levitus_climatology] gg123456789012345678901
show grid gg123456789012345678901
let f = sst[y=20s:20n:.1,d=coads_climatology]
DEFINE GRID/LIKE=f/x=temp[d=levitus_climatology] gg123456789012345678902
cancel variable f
show grid gg123456789012345678902
show grid/dynamic

! demonstrate proper management of dynamic axes
DEFINE GRID/LIKE=gg123456789012345678902 gg123456789012345678903
show grid/dynamic
DEFINE GRID/like=temp[d=levitus_climatology] gg123456789012345678902
show grid gg123456789012345678902
show grid/dynamic

! SET GRID using a user-defined variable
let g = sst[x=0:30:.1,d=coads_climatology]
set grid g
show grid

! The SET GRID (default) definition should be protected -- not altered
load/d=coads_climatology sst[y=-10:10:.1,l=1,x=160e]
show grid
show grid/dynamic

! deliberate errors
set mode ignore
load/x=160e/y=5s temp[d=2,k=1,g=no_exist12345678901234567890]	! non-existent target variable

set mode/last ignore

go bn_reset

! dynamic grid commands

use coads_climatology
use levitus_climatology

DEFINE GRID/LIKE="temp[d=2,gx=sst[d=1],y=10s:2s:.2] + 5" mygrid_123456789012345678901234567890
SHOW GRID mygrid_123456789012345678901234567890
