python和idl,在Python中调用IDL脚本

I would like to run an IDL script in a python code, since I need to analyse the results of IDL code later in the python script but I have no idea how it works.

I want to call this IDL script for example in a python code:

pro plotgaussian, center, sigma, X=x, Y=y

x = findgen(1000) / 999; numbers running 0 to 1 in steps of 0.001

x = x * 6 * sigma - 3 * sigma; widen x to range over 6 sigma

x = x + center; center the x range on the bell curve center

arg = ((x – center)/sigma)^2

y = exp(-arg)

plot, x, y

end

How could I do it?

解决方案

The newest version of IDL (8.5) supports this natively, they provide their own bidirectional bridge for calling Python from IDL, and IDL from Python. Their docs are here:

http://www.exelisvis.com/docs/pythontoidl.html

Some example code from their docs:

>>> from idlpy import IDL

>>> arr = IDL.findgen(100)/50*3.14159

>>> x = 50*IDL.sin(arr)

>>> y = 50*IDL.cos(arr)

>>> m = IDL.map(test=1)

% Compiled module: MAP.

>>> p = IDL.plot(x - 90, y, 'r-o2', overplot=1)

% Compiled module: PLOT.

>>> p = IDL.plot(x + 90, y, 'b-o2', overplot=1)

>>> m.save('map.png', resolution=96, border=0, transparent=1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IDL文件是Interface Definition Language的缩写,通常用于描述软件组件之间的接口和通信协议。在Python,可以使用IDL编译器来生成Python代码,然后使用生成的Python代码来读取IDL文件。 以下是使用omniORBpy库读取IDL文件的示例代码: ```python import CORBA import CosNaming # Load the IDL file idl_file = "example.idl" idl_module = "Example" # Initialize the ORB orb = CORBA.ORB_init() # Read the IDL file idl_file = open(idl_file).read() # Compile the IDL file idl_compiler = CORBA.idl_compiler() idl_compiler.compile_string(idl_file) # Import the generated Python module example_module = __import__(idl_module) # Get the naming service name_service = orb.resolve_initial_references("NameService") # Bind the object to the naming service example_object = example_module.ExampleObject() name = [CosNaming.NameComponent("example", "object")] name_service_context = name_service._narrow(CosNaming.NamingContext) name_service_context.rebind(name, example_object) # Get the object from the naming service example_object = name_service_context.resolve(name) # Use the object result = example_object.example_method() ``` 在上面的示例代码,我们首先使用CORBA库初始化了ORB。然后,我们使用IDL编译器编译IDL文件,并导入已生成的Python模块。之后,我们通过解析初始引用来获取命名服务。最后,我们将对象绑定到命名服务,并从命名服务获取对象,然后使用对象的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值