Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drawing irregular grid, and trying to debug code in general? 1

Status
Not open for further replies.

hydrocomputer

Programmer
Nov 29, 2004
6
US
I am trying to write substantial algorithms in postscript and finding
it hard going. There are two questions inherent in this post. First,
how can I solve the problem. Second, rather than just giving me the
answers, is there any decent way of stepping through postscript code
so I can debug it? I am using gs on linux; if there are better tools,
great. If there aren't, do any of you have little subroutines to
display intermediate values, or techniques to help? I programmed in
forth ages ago but find the stack machine to be difficult to code. No
doubt part of that is just my rusty skills.

First, I want to setup a color table to index values 0-127 to rgb triples.
I try to index from [0 0 1] to [1 0 0]

384 /palettesize store
/palettesize load string /nyhopscolormap store
/red 0 store
/green 0 store
/blue 255 store
0 3 /palettesize load
{
/i exch store
/nyhopscolormap load /i load /red/ load put
/nyhopscolormap load /i load 1 add /green load put
/nyhopscolormap load /i load 2 add /blue load put
/red load 2 add /red store
/blue load 2 add /blue store
} for

[/nyhops DeviceRGB 255 /nyhopscolormap load] setcolorspace



Then, I want to create an array of x,y locations, each with a value.
A low-tech way might be:

[
[-74,40, 1], [-73.99,40.05, 1.2], [-73.99, 40.085, 1.21]
[-73.95,40, 1.01], [-73.956,40.061, 1.11], [-73.99, 40.09, 1.14]
[-73.92,40, 1.01], [-73.912,40.059, 1.11], [-73.93, 40.089, 1.4]
]

This describes a 2d grid. I'm aware that I could encode this better
using ascii or binary, but that's a detail. I'd like to traverse this grid, connecting each adjacent quadrilateral (they aren't squares), coloring them.

I could of course just generate code like:

1 setcolor
newpath
-74,40 moveto
-73.99,40.05 lineto
-73.95,40 lineto
-73.956,40.061 lineto
closepath
fill


and just repeat, but this bothers me. I'd rather be able to write a
loop that processes this repettetive data and just process the
data. Whenever I try, it fails, and I have no good way to debug pieces
at a time until I have a working entity. If I mistype a token, I can
see in the dump from gs that it failed on that token, but otherwise I
just get an error at position xxxx which is better than nothing, but
not much better (and I am trying to find byte xxx in emacs, which no doubt has a command). Any suggestions would be greatfully appreciated.
 
You can yse -dESTACKPRINT flag to print out the execution stack in Ghostscript. You can also check what shading fill
can do for you in Level 3.

Regarding the grid structure, the arrays use memory and cause expensive garbage collection. Besides, even a simple PS operator takes over 100 computer commands. I vote for the moveto-lineto approach. Besides, PostScript is almost always converted to PDF, which unrolls all the loops. So why bother?

Your PostScript expert is just a click away.
 
There is a program call PSAlter ( )which appears to be a PostScript debugger.

I have NO experience with the product and cannot say whether it would help solve your problems.

It costs about £200 + VAT so it's not an insignificant investment!

Let me know if you DO purchase and it's any good!!

regards
Mark H., AFX
 
afx- see my previous post.

Quite will let you have a evaluation key if you ask.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top