! bn_iin_regrid.jnl
! @IIN as a regridding transform See Ticket 2346

def ax/edge/x=0:10:1 aline
let a = mod(.5+x[gx=aline],2)

let xlo = xboxlo[gx=a]
def ax/x aline_edges = xcat(xlo[i=1], xboxhi[gx=a])

! new @IIN regridding
show axis/x aline_edges

let c = a[gx=aline_edges@iin]
list a
list c


def ax/edge/x=0:10:1 aline
let a = mod(.5+x[gx=aline],2)

! Intentional error

set mode ignore
! Different delta

define axis/x=0.5:10.5:0.5 alinenew
list a[gx=alinenew@iin]

set mode/last ignore


! result out of range, returns missing
define axis/x=100:111:1 alinenew
list a[gx=alinenew@iin]

! partially out of range 
define axis/x=2.5:15.5:1 alinenew
list a[gx=alinenew@iin]

! same range, outer boxes 
define axis/x=-0.5:10.5:1 alinenew
list a[gx=alinenew@iin]
can mem
! plots in different directions

can view; can var/all
! In X

set win/asp=0.5
set v left
def ax/edge/x=0:10:1 aline
let a = mod(.5+x[gx=aline],2)
plot/step=con/vl=-1:6:1/hl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[x=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let xlo = xboxlo[gx=a]
def ax/x aline_edges = xcat(xlo[i=1], xboxhi[gx=a])
let a_iin_edges = a_iin[gx=aline_edges@asn]
let a_int = IF i[gx=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[x=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding

show axis/x aline_edges
let c = a[gx=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c

set v right
let b = 1+0*a
plot/step=con/vl=-1:12:1/hl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[x=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[gx=aline_edges@asn]
let b_int = IF i[gx=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[x=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[gx=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/z=1:2:1 otheraxis
let b2d = b + z[gz=otheraxis]
list b2d[gx=aline_edges@iin]


can view; can var/all
! In Y

set win/asp=0.5
set v left
def ax/edge/y=0:10:1 aline
let a = mod(.5+y[gy=aline],2)
plot/step=con/vl=-1:6:1/hl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[y=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let ylo = yboxlo[gy=a]
def ax/y aline_edges = ycat(ylo[j=1], yboxhi[gy=a])

let a_iin_edges = a_iin[gy=aline_edges@asn]
let a_int = IF j[gy=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[y=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding
let c = a[gy=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c


set v right
let b = 1+0*a
plot/step=con/vl=-1:12:1/hl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[y=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[gy=aline_edges@asn]
let b_int = IF j[gy=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[y=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[gy=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/z=1:2:1 otheraxis
let b2d = b + z[gz=otheraxis]
list b2d[gy=aline_edges@iin]


can view; can var/all
! in Z

set win/asp=0.5
set v left
def ax/edge/z=0:10:1 aline
let a = mod(.5+z[gz=aline],2)
plot/step=con/hl=-1:6:1/vl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[z=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let zlo = zboxlo[gz=a]
def ax/z aline_edges = zcat(zlo[k=1], zboxhi[gz=a])

let a_iin_edges = a_iin[gz=aline_edges@asn]
let a_int = IF k[gz=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[z=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding
let c = a[gz=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c

set v right
let b = 1+0*a
plot/step=con/hl=-1:12:1/vl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[z=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[gz=aline_edges@asn]
let b_int = IF k[gz=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[z=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[gz=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/e=1:2:1 otheraxis
let b2d = b + _e[ge=otheraxis]
list b2d[gz=aline_edges@iin]


can view; can var/all
! In T

set win/asp=0.5
set v left
def ax/edge/t=0:10:1 aline
let a = mod(.5+t[gt=aline],2)
plot/step=con/vl=-1:6:1/hl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[t=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let tlo = tboxlo[gt=a]
def ax/t aline_edges = tcat(tlo[l=1], tboxhi[gt=a])

let a_iin_edges = a_iin[gt=aline_edges@asn]
let a_int = IF l[gt=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[t=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding
let c = a[gt=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c

set v right
let b = 1+0*a
plot/step=con/vl=-1:12:1/hl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[t=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[gt=aline_edges@asn]
let b_int = IF l[gt=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[t=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[gt=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/z=1:2:1 otheraxis
let b2d = b + z[gz=otheraxis]
list b2d[gt=aline_edges@iin]


can view; can var/all
! in E

set win/asp=0.5
set v left
def ax/edge/e=0:10:1 aline
let a = mod(.5+_e[ge=aline],2)
plot/step=con/vl=-1:6:1/hl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[e=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let elo = eboxlo[ge=a]
def ax/e aline_edges = ecat(elo[m=1], eboxhi[ge=a])

let a_iin_edges = a_iin[ge=aline_edges@asn]
let a_int = IF _m[ge=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[e=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding
let c = a[ge=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c

set v right
let b = 1+0*a
plot/step=con/hl=-1:12:1/vl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[e=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[ge=aline_edges@asn]
let b_int = IF _m[ge=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[e=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[ge=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/z=1:2:1 otheraxis
let b2d = b + z[gz=otheraxis]
list b2d[ge=aline_edges@iin]


can view; can var/all
! In F

set win/asp=0.5
set v left
def ax/edge/f=0:10:1 aline
let a = mod(.5+_f[gf=aline],2)
plot/step=con/vl=-1:6:1/hl=-1:11:1/grat=dash/col=green/thic=3 a
let a_iin = a[f=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 a_iin
let flo = fboxlo[gf=a]
def ax/f aline_edges = fcat(flo[n=1], fboxhi[gf=a])

let a_iin_edges = a_iin[gf=aline_edges@asn]
let a_int = IF _n[gf=aline_edges] EQ 1 THEN 0 ELSE a_iin_edges[f=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 a_int


! new @IIN regridding
let c = a[gf=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 c

set v right
let b = 1+0*a
plot/step=con/vl=-1:12:1/hl=-1:11:1/grat=dash/col=green/thic=3 b
let b_iin = b[f=@iin]
plot/ov/line/sym=2/si=.1/col=2/thic=2 b_iin
let b_iin_edges = b_iin[gf=aline_edges@asn]
let b_int = IF _n[gf=aline_edges] EQ 1 THEN 0 ELSE b_iin_edges[f=@shf:-1]
plot/ov/line/sym=28/si=.1/col=purple/thic=2 b_int

! new @IIN regridding
let d = b[gf=aline_edges@iin]
plot/ov/line/sym=19/si=.1/col=light/thic=1 d

list d
define axis/z=1:2:1 otheraxis
let b2d = b + z[gz=otheraxis]
list b2d[gf=aline_edges@iin]
