青未了分享 http://blog.sciencenet.cn/u/yanghang

博文

IDL混合编程

已有 4621 次阅读 2019-2-11 22:40 |个人分类:IDL学习笔记|系统分类:科研笔记

混合编程是同时使用多种语言实现一个业务化系统的编程方式,目的是为了充分发挥不同语言的优势。这种编程方式下需要各个语言提供方便的扩展和外部接口调用方法。本部分主要是讲解IDL调用外部语言与其他常用语言调用IDL的方式。

一、IDL功能扩展

1.调用可执行程序

1.1 SPAWN

IDL可以直接调用外部可执行程序。例如IDL直接调用win系统中的画图程序:

spawn, 'mspaint'   ;启动DOS命令行界面

spawn, 'mspaint',/noshell ;不启动DOS命令行界面

除可执行程序外,还可以调用其他外部文件,调用时会执行默认程序打开文件:

SPAWN, 'D:\IDLPROJ\IQA\veg.txt'   ;启动DOS命令行界面

SPAWN, 'D:\IDLPROJ\IQA\veg.txt',/hide  ;不启动DOS命令行界面

Syntax

SPAWN [, Command [, Result] [, ErrResult] ]

Keywords (all platforms): [, COUNT=variable] [, EXIT_STATUS=variable] [ ,/NOSHELL] [, /NULL_STDIN] [, PID=variable] [, /STDERR] [, UNIT=variable {Command required, Result and ErrResult not allowed}]

UNIX-Only Keywords: [, /NOTTYRESET] [, /SH]

Windows-Only Keywords: [, /HIDE] [, /LOG_OUTPUT] [, /NOWAIT]

仅调用DOS命令行界面(To simply spawn a shell process from within IDL, enter the command):

IDL> SPAWN

在Windows系统中,IDL的SPAWN命令其实就是在执行CMD命令。

注意:

  • 直接利用SPAWN启动外部程序或文件时,如果路径中含有空格,则启动失败。

  • 如果程序路径中含有空格解决办法是用""把路径引用:

    SPAWN, '"D:\test blank\veg.txt"'  ;启动后DOS界面不退出

    SPAWN, 'start "" "D:\test blank\veg.txt"'   ;启动后DOS界面退出

    SPAWN, 'start "" "D:\test blank\veg.txt"' ,/hide  ;不启动DOS界面 

  • start:

       SPAWN, 'D:\test blank\veg.txt'  ;程序不报错

       SPAWN, 'start D:\test blank\veg.txt'  ;程序报错,见下图,因为路径中含有空格

33.bmp


1.2 OnLine_Help

OnLine_Help是一个帮助启动程序,调用格式为:

Syntax

ONLINE_HELP [, Value] [, BOOK=‘filename’] [, /FULL_PATH] [, TITLE = 'title']

Windows-Only Keywords: [, /CONTEXT]

BOOK:指定下面四种类型的帮助文件:

Extension

File Type

Behavior

.html.htm

HTML

Opens the specified HTML file in IDL's help viewer. If the Value argument is present, it is treated as an anchor value and appended to the URL for the specified HTML file. In most cases, this will cause the browser to position the file content so that the specified anchor is at the top of the viewing window. If the anchor is not present in the HTML file, the browser generally ignores it quietly.

Note: See Displaying HTML and PDF Files under UNIX for additional information.

.chm

Windows HTML Help

Opens the specified Windows HTML Help file. If the Value argument is present, the Index tab of the HTML Help viewer is positioned to display the closest matching value. See also the CONTEXT keyword.

.hlp

Windows Help

Opens the specified Windows Help file. If the Value argument is present, the Index tab of the Help viewer is positioned to display the closest matching value. See also the CONTEXT keyword.

.pdf

Acrobat

Opens the specified PDF file in the system default PDF viewer. The Value argument is quietly ignored.

Note: See Displaying HTML and PDF Files under UNIX for additional information.

None

Any type

Searches the directories specified by the !HELP_PATH environment variable for a file whose base name matches the specified value, in this order: .adp.chm (Windows only), .hlp (Windows only), .pdf.html.htm. The first file found is opened and the Value argument interpreted as described by this table.

Note: Topics in the IDL help system will not be found by this mechanism.


2.调用DLL

Dynamic Link Library,动态链接库。DLL是一个可由多个程序同时使用的代码或数据的库,动态库提供进程调用外部功能函数的标准方法。通过使用DLL,程序可以由相对独立的组件组成,程序在运行时将各个模块动态的加载到主程序中。由于模块是彼此独立的,而且模块只在相应的功能被请求时才加载,所以程序的加载速度很快。

通过CALL_EXTERNAL命令IDL能够调用特定的DLL,从而实现IDL调用其他语言已有功能模块。

Syntax

Result = CALL_EXTERNAL(Image, Entry [, P0, ..., PN-1] [, /ALL_VALUE] [, /B_VALUE | , /D_VALUE | , /F_VALUE | , /I_VALUE | , /L64_VALUE | , /S_VALUE | , /UI_VALUE | , /UL_VALUE | , /UL64_VALUE] [, /CDECL] [, RETURN_TYPE=value] [, /UNLOAD] [, VALUE=byte_array] [, WRITE_WRAPPER=wrapper_file] [, /AUTO_GLUE] [, CC=string] [, COMPILE_DIRECTORY=string] [, EXTRA_CFLAGS=string] [, EXTRA_LFLAGS=string] [, /IGNORE_EXISTING_GLUE] [, LD=string] [, /NOCLEANUP] [, /SHOW_ALL_OUTPUT] [, /VERBOSE] )

关键参数:

Image

The name of the file, which must be a sharable library (UNIX), or DLL (Windows), which contains the routine to be called.

Entry

A string containing the name of the symbol in the library which is the entry point of the routine to be called.

P0, ..., PN-1

The parameters to be passed to the external routine. All array and structure arguments are passed by reference (address). The default is to also pass scalars by reference, but the ALL_VALUE or VALUE keywords can be used to pass them by value. Care must be taken to ensure that the type, structure, and passing mechanism of the parameters passed to the external routine match what it expects. There are some restrictions on data types that can be passed by value, and the user needs to be aware of how IDL passes strings. Both issues discussed in further detail below.



3.调用DLM


4.调用COM和ActiveX


5.调用Java


二其他语言调用IDL



https://blog.sciencenet.cn/blog-346157-1161712.html

上一篇:IDL程序发布与部署
下一篇:IDL基础语法汇总
收藏 IP: 223.72.67.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-12 01:12

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部