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


! NOTE: All of the *polar* journal files are superseded by the map projection 
! capabilities of version 5.0.   Run the script  mp_demo  for an introduction.


! Description: extract (sample) data for a 2D polar plot

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

! usage:   GO convert_to_polar_2d variable [#_points] [fill] [file]

! 	     variable:  variable or expression to be plotted.
!			Must include explicit qualifiers with region
!			encompassing the area to be plotted 
! (optional) #_points:	number of points on X and Y axes of the final
!			plot (essentially, the resolution of the plot)
!			Use #_points=63 for FNOC (?), #_points=65 for NMC (?)
! (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 = polar_sampled_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_polar_2d variable [n by n points] [HOLES] [file]%
query/ignore $3%HOLE|FILL|HOLES|HOLE|<Argument 3 must be "FILL" or "HOLES"%

! define the output grid (with #_points resolution argument)
GO projected_map_grid $2"201"

! define the polar projection equations
GO polar_map_inv_eqns gproj$2"201"

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

! now sample it
user/command=sample/opt2=c/file=$4"polar_sampled_points.dat"/form=unf:$2"201"/opt1=$3"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=gproj$2"201"/var=polar/form=unf/col=$2"201" $4"polar_sampled_points.dat"
set variable/title=$1 polar
set data/restore

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

set mode/last verify


message/continue "NOTE: The map projection capabilities beginning with Ferret v5.0"
message/continue "provide far more flexibility for plots with curvilinear coordinates."
message/continue "Run the script  mp_demo  for an introduction"
