! bn_set_axis_name.jnl
! ticket 2160 Implementing new qualifier SET AXIS/NAME
! 3/2014
!
!
! Prepare a dataset with a time axis

define axis/t=1-may-2010:5-may-2010:1/units=days daysaxis
let a = t[gt=daysaxis]
save/clobber/file=a.nc a

cancel variable a
cancel axis daysaxis

!  We define some axis, then open a dataset with an axis of that name.

define axis/t=1-jan-2000:31-jan-2000:1/units=days daysaxis

use a.nc

! The axis in the dataset has been renamed.
say `a,return=taxis`

! So, rename our user-defined axis
set axis/name=days2000 daysaxis

! and now rename the one from the dataset back to its original name
set axis/name=daysaxis `a,return=taxis`
sh grid a

cancel data/all

! If an axis is used in several datsets, renaming it of course
! changes the name for all grids.
! The attribute structure gets updated as well.

! Make several datasets with the same x axis.
define axis/x=1:13:1/units=meters x13axis
let a = x[gx=x13axis]
let b = 3*x[gx=x13axis]
let c = 5*x[gx=x13axis]
save/clobber/file=a.nc a
save/clobber/file=b.nc b
save/clobber/file=c.nc c

can var/all
can axis x13axis

! Open them in Ferret; all grids are the same.
use a.nc, b.nc, c.nc
say `a[d=1],return=xaxis`
say `b[d=2],return=xaxis`
say `c[d=3],return=xaxis`

! Rename the axis
set axis/name=x_in_meters x13axis
say `a[d=1],return=xaxis`
say `b[d=2],return=xaxis`
say `c[d=3],return=xaxis`

! For SHOW DAT/ATT we get info from the attribute structure.
! It has the udated name.
sh dat/att

! Intentional errors
set mode ignore

! Name already in use
set axis/name=days2000 x_in_meters

! Missing or illegal name
set axis/name x_in_meters
set axis/name=45 x_in_meters
set axis/name=.fr x_in_meters

set mode/last ignore
