IDL 可以将字符串作为代码进行评估吗?
IDL 中是否有任何功能可以允许将字符串作为代码进行计算?
或者,如果做不到这一点,是否有一种很好的动态方式在函数中包含 /KEYWORD ?例如,如果我想询问用户想要什么类型的地图投影,有没有办法可以很好地做到这一点,而无需使用 /Projection_Type 关键字的大量 if/case 语句?
即使用户选项数量很少,这些组合也会导致 if/case 语句很快失控,无法处理所有可能的选项。
Is there any functionality in IDL that will allow it to evaluate a a string as code?
Or, failing that, is there a nice, dynamic way of including /KEYWORD in functions? For example, if I wanted to ask them for what type of map projection the user wants, is there a way to do it nicely, without large if/case statements for the /Projection_Type keyword it needs?
With even a small number of user options, the combinations would cause if/case statements to get out of hand very quickly to handle all the possible options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择是使用 case 语句,因为您不能相信您的用户会为 Projection_Type 输入与您期望的关键字相同的字符串。
不过,如果您打算执行类似的操作,则可以使用 EXECUTE 函数将字符串视为 IDL 语句:
Result = EXECUTE(String [, QuietCompile] [, QuietExecution])
编辑后添加,还有 CALL_FUNCTION 和 CALL_PROCEDURE 速度更快,但灵活性可能较差。在 IDL 帮助中查找所有内容,看看哪些对您有用。
The best bet is to use a case statement because you can't trust that your user is going to type in the same string for Projection_Type that you're expecting as in the keyword.
Though if you are set on doing something like this, there is the EXECUTE function that treats a string as an IDL statement:
Result = EXECUTE(String [, QuietCompile] [, QuietExecution])
Edited to add, there's also CALL_FUNCTION and CALL_PROCEDURE that are faster but maybe less flexible. Look them all up in the IDL help and see what works for you.