Postscrip/Ghostscript 如何将栈顶保存为字典项

Postscrip/Ghostscript How to save top of stack as a dictionary item

我在Linux下使用Ghostscript,感觉还是个新手。我想将值保存在堆栈顶部,以便以后可以调用该值,而不必执行复杂的堆栈操作来检索它。该值将是从数据文件中读取的纬度,因此我无法将其直接合并到程序中。在我看来,显而易见的解决方案是将值作为 key/value 对存储在 userdict 中,类似于(保存纬度值):

2 dict coords
coords lat [some code to get the value of the latitude on the stack] put

有人可以解释一下如何处理括号中的位吗?很可能是我全错了,在这种情况下,请问我该怎么办?

背景:我正在编写一个程序来使用文件中的纬度和经度数据绘制可以剪切并粘贴到球上以制作世界地球仪的血块。缩放经度以使其正确拟合需要相当多的数学知识;我使用的 gores.The 数据中的 y 是 gnuplot 安装中包含的 world.dat 中的一组 1320 个坐标。

你还没有真正付出足够的努力,'coords' 和 'lat' 是什么?

您在操作数堆栈上创建了一个包含 2 个条目的字典,'coords' 是一个可执行程序来填充它吗?如果是 return 操作数堆栈上的字典?

通过按照您的方式执行 'put',您将在当前字典中定义一个数组,其键为 'lat',无论对象类型是什么。然后您将需要再次访问 'lat' 以便从字典中检索对象(或在字典上使用 forall,但仍然很难检索特定值)。

为了回答你的问题,这将定义当前字典中操作数堆栈顶部的值:

5       %% put an object on top of the dictionary stack, stack is now: 5
/Saved  %% create a name object on the operand stack, stack is now: 5 /Saved
exch    %% exchange the objects, stack is now: /Saved 5
def     %% define the value on the stack in the current dictionary, using the
        %% key also on the stack

请注意,这在 current 词典中被拒绝,该词典位于词典堆栈的顶部。要在 userdict 中明确定义它,请执行

5          %% put an object on the operand stack, stack is now: 5
/Saved     %% put a name object on the operand stack, stack is now: 5 /Saved
exch       %% exchange the objects, stack is now: /Saved 5
userdict   %% put a pointer to userdict on the operand stack, stack is now /Saved 5 <<userdict>>
3 1 roll   %% roll the stack, stack is now: <<userdict>> /Saved 5
put        %% put the value from the operand stack, using the key from the operand stack, in the dictionary also on the operand stack