/*
 * VerticalWave.virx
 * Copyright (c)1992 Bruno Costa & Lucia Darsa
 */

options results

signal on HALT
signal on SYNTAX
signal on FAILURE

call openmath

lockgui

form = '"BOOL,_TO Window,0|'		||,
       'BOOL,Just _Selected Vertices,0|'||,
       'STR,_Amplitude:,5.0,6|'		||,
       'STR,Number of _Waves:,3,6"'

requestform TITLE '"Vertical Wave"' form
if rc >= 5 then
  signal HALT

parse var result window '|' selected '|' amplitude '|' nwaves

if window = 0 then
  winname = 'FROM'
else
  winname = 'TO'

getdensity
parse var result nrows ncols

if selected = 1 then
  getmesh winname 'SELECTED'
else
  getmesh winname

parse var result width height inmesh


pi = 3.14159
k = (2 * pi) / (width / nwaves)

outmesh = ''
sel = 1
do row = 1 to nrows
  do col = 1 to ncols
    if selected = 1 then
      parse var inmesh inx iny sel inmesh
    else
      parse var inmesh inx iny inmesh

    outx = inx
    if sel  &  row > 1  &  row < nrows then
      outy = iny + amplitude * sin(k * inx)
    else
      outy = iny
    outmesh = outmesh outx outy
  end
end

setmesh winname '"'outmesh'"'

unlockgui
exit 0

 /* add rexxmathlib.library if it is not already open */
openmath: procedure
 if ~show('L', "rexxmathlib.library") then do
   if ~addlib("rexxmathlib.library", 0, -30, 0) then do
     requestnotify "could not open rexxmathlib.library"
     exit 20
   end
 end
 return

BREAK_C:
HALT:
 unlockgui
 exit 20

FAILURE:
 requestnotify '"Host *"'address()'*" returned an error (severity 'rc')*nexecuting' compress(sourceline(2),'* ') 'at line' SIGL'"'
 unlockgui
 exit 20

SYNTAX:
 requestnotify '"'errortext(rc)'*nexecuting' compress(sourceline(2),'* ') 'at line' SIGL'"'
 unlockgui
 exit 20
