Hi Ansley,Thanks for catching my omission of the shell script get_vertices in my original email. Since some of my applications use polydef.jnl in situations where I don't need or want to close the polygon, I chose instead to make a variants polydef_close.jnl and get_vertices_close that do the closing. Either choice would work with InsidePolygon.jnl . Also the lengthy email may have masked the role of x0,y0.
So another demo and graphic are attached to clarify how the scheme works; it selects cells in the underlying grid whose centers fall within the user-prescribed polygon. The variables x0,y0 identify the x and y-axes of the grid.
! shade a coarsely gridded field and mark cell centers shade/i=1:10/j=1:8 i+j let x0=x[x=1:10] ; let y0=y[y=1:8]plot/o/vs/nolab/sym=17/i=1:10/j=1:8/set x0+0*y0,y0+0*x0 ; ppl pen,1,7 ; ppl plot/over
! select polygon vertices (closed) and plot boundary go polydef_close poly/o/nolab/line=2 vx,vy! alternately a vertex file for the closed polygon might be otherwise available, in which case
! file/form=free/var=vx,vy/g=gz vx,vy! where "gz" is a 1-D z-axis grid for the vertex coords, could substitute for "go polydef..."
! identify and highlight the cells whose centers fall inside the polygon go InsidePolygon shade/o/nolab/pal=red/pat=dark_vertical insideNOTE in the demo plot that cells are treated as inside or outside which has an implication for area averages or integrals that might result from using the "inside" variable as a mask. If the cells adjacent to the boundary are too many, it might be a good idea to regrid the data to be masked to a finer grid to reduce the raggedness of the polygon edges. Another thing to note is that the polygon vertex file "vertices.xy" is read in along the z-axis. If one were using the scheme for a vertical section, a variant employing another axis might be appropriate.
Mick
------------------------------------------------------------------------
Attachment:
get_vertices_close
Description: video/flv
! polydef_close : use mouse click to define polygon vertices; ! the shell script get_vertices_close will ! close the polygon can mode verify let done=0 ; sp rm -f vertices.xy say "****************************************************" say "* *" say "* Add polygon vertices by mouse clicks. Terminate *" say "* by clicking to the left of the plot area. *" say "* *" say "****************************************************" ! add new vertices to the file vertices.xy repeat/range=1:1000 go add_vertex ! then read in the resulting file sp get_vertices_close ; go get_vertices set mode verify