\cancel mode verify
! 2/94 - convert_to_fnoc_2d.jnl

! Description: extract (sample) lat/lon data onto the FNOC polar grid

! Note: the variable "polar_rotation" needs to be pre-defined

! usage:   GO convert_to_fnoc_2d variable [fill] [file]

! 	     variable:  variable or expression to be plotted.
!			Must include explicit qualifiers with region
!			encompassing the area to be plotted 
! (optional) fill:	Either FILL or HOLE(default) to indicate how points
!			bordering on missing values should be treated
! (optional) file:	name of file to receive the sampled points
!			Default = fnoc_points.dat
!			Note: the format of this file will be unformatted
!			with #_points columns per record.

! check that parameters are OK to the best we can
query/ignore $1%<Use: GO convert_to_fnoc_2d variable [HOLES] [file]%
query/ignore $2%HOLE|FILL|HOLES|HOLE|<Argument 2 must be "FILL" or "HOLES"%

! define the rotation parameter as per FNOC
LET/quiet polar_rotation = 100

! define the output grid (with #_points resolution argument)
GO fnoc_map_grid

! define the polar projection equations
GO polar_map_inv_eqns gprojfnoc

! prepare for sampling of data at polar-projecting points
cancel data/noerror $3"fnoc_points.dat"
sp rm -f $3"fnoc_points.dat"
set data/save

! now sample it
user/command=sample/opt2=c/file=$3"fnoc_points.dat"/form=unf:63/opt1=$2"HOLE|FILL|HOLES|HOLE|"-STANDARD_BAD $1,polar_xdeg[x=-1:1,y=-1:1],polar_ydeg[x=-1:1,y=-1:1],1/0,1/0

! now prepare to read back the results
file/grid=gprojfnoc/var=polar/form=unf/col=63 $3"fnoc_points.dat"
set variable/title=$1 polar
set data/restore

! message to user
message/continue Note: Polar-projected data is variable "polar" in $3"fnoc_points.dat"

set mode/last verify
