adesutherland / CREXX

REXX Language implementation
Other
13 stars 3 forks source link

array loses its contents #359

Open rvjansen opened 1 year ago

rvjansen commented 1 year ago

I'm stumped at the moment because when I comment out procedure transformCoordinates, the points array contains valid coordinates in writeSVG. When transformCoordinates is called, the points array only contains comma's.

/* rexx                                                                 */
/* plot from stdin to svg - with a graphics capable shell like kitty    */
/* freely inspired on Guff and Kate's awk version of it                 */
/* rvj 2023-07-21 v0                                                    */

options levelb dashcomments
import rxfnsb
namespace rexxplot expose height width points

main: procedure

points=.string[]
i=0;
maxx=0
maxy=0
do while lines('testseq.txt')
  i=i+1;
  points[i]=linein('testseq.txt')
end

say 'read in'   points[0]-1 'coordinates'
height= 450
width = 600

call transformCoordinates

call writeSVG

transformCoordinates: procedure
do i=1 to points[0]-1
  say '<<<<<<' points[i]
  if pos(',',points[i])>0 then commapos=pos(',',points[i])
  say commapos '>>>' points[i]
  x=left(points[i],commapos-1)
  say 'x:' height-x
  y=substr(points[i],commapos+1)
  say 'y:' width-y
  say '>>>>>>' points[i]
end

writeSVG: procedure
say "<?xml version='1.0'?>"
say "<svg xmlns='http://www.w3.org/2000/svg' width='"width"'",
"height='"height"' version='1.1'>"
call grid
say "<polyline stroke='#0072B2ff' stroke-width='1.5' fill='none' points='"
do j=1 to points[0]-1
  say points[j]
end
say "'/>"
say "</svg>"

grid: procedure
say "<defs>"
say "    <pattern id='smallGrid' width='8' height='8' patternUnits='userSpaceOnUse'>"
say "      <path d='M 8 0 L 0 0 0 8' fill='none' stroke='gray' stroke-width='0.5'/>"
say "    </pattern>"
say "    <pattern id='grid' width='80' height='80' patternUnits='userSpaceOnUse'>"
say "      <rect width='80' height='80' fill='url(#smallGrid)'/>"
say "      <path d='M 80 0 L 0 0 0 80' fill='none' stroke='gray' stroke-width='1'/>"
say "    </pattern>"
say "</defs>"
say "<rect width='1000' height='1000' fill='url(#grid)' />"

the input file testseq.txt contains (abbreviated but same symptoms):

1,1
2,2
3,3
4,4
5,5
6,6
7,7
8,8
9,9
10,10