What’s New in IDL 5.4

Download Report

Transcript What’s New in IDL 5.4

The Interactive Data
Language
交互式数据语言
功能简介
IDL是进行数据分析、
可视化及跨平台应用开
发的最佳选择。IDL集
可视、交互分析、大型
商业开发为一体,为您
提供了最完善、最灵活
最有效的开发环境。
(参考 idl5.5.ppt)
IDL培训提纲

IDL简介及应用
 IDL程序特点
 命令行操作
 数据输入输出
 图像与信号处理
 矩阵操作
 界面设计
对象图形
 对象操作
 参数传递
 与外部语言接口
 数据库接口
 例程分析
 回答问题

IDL程序特点
——宽松的语法检查机制
分隔符为“,”,而非空格
 不分大小写
 变量无需事先说明

IDL符号

$
– 作为一行的第一个字符时,返回到操作系统
下,如:$ dir
– 作为一行的最后一个字符时,相当于一行未
写完,换行。
;后面是注释
 @ 批作业 如:@test

IDL命令行








A=dist(100)
Plot,a
Tv,a
Erase
Tvscl,a
Surface,a
Shade_surf,a
Shade_surf,a,az=60






Zvalue=0.5
Contour,a
Contour,a,nlevels=10
Contour,a,nlevels=10,$,
/fill
Contour,a,nlevels=10,$,
/follow
Contour,a,nlevels=10,$,
/t3d
变量命名规则
正确:
 reade6_$file
 only_8_bit
 ComputerType
 variables
 _day_of_year
错误:
 name.last
 third%file
 4th_list
 $temp
变量名称长度不超过255个字符,但变量大小取决于计算机配置和
操作系统。
IDL变量类型
Type
Byte
Integer
Uint
Long
Ulong
Long64
Ulong64
Float
Double
Complex
Dcomplex
String
Pointer
Object
Len
1
2
2
4
4
8
8
4
8
8
16
?
4
4
Creation
A=5B
B=0;b=0S
C=0U
D=0L
E=0UL
F=0LL
G=0ULL
H=0.0
I=0.0D
J=complex(1.0,0.0)
K=dcomplex(1.0,0.
0)
L=’hello’
M=ptr_new()
N=obj_new()
Array
Bytarr
Intarr
Uintarr
Lonarr
Ulonarr
Long64arr
Ulon64arr
Fltarr
Dblarr
Complexarr
Dcomplexar
rStrarr
Ptrarr
Objarr
Conversion
Byte
Fix
unit
Long
Ulong
Long64
Ulong64
Float
Double
Complex
Dcomplex
String
-----
IDL 变量

Scalar
 Array (1—8维)
 Structure(结构)
系统 Keyword

系统Keyword
– !dpi (3.1415926)
– !p 控制显示 如:!p.font, !p.color
– !d (device,对设备进行控制)
– 如:device,get_screen_size=view
24bit显卡下显示8位假彩色图像,用
Device,decompose=0,(设置成8bit 256色)
矩阵操作

A=bytarr(512,512)
列
行
b=tan(a)+10
子区处理:
A(*,1)表示第2行的所有列
A(*,1:10)
矩阵操作
若a为一二维数组,c=[10,15,20],
则A(c)将是一稀疏矩阵,只提取a中第10,
15,20个元素,如可用来提取河流。
C=where(a,max=15,min=0)
a( c)=255
将a中很暗的值变为255。
取字区还可实现非常多的局部操作。

WHERE 函数
Indices=where(data gt 0.4 and data lt 0.5)
Data[indices]=1.0
矩阵操作
search2D 二维数组中在一定值域范围内
以一初始点为准,搜索与它连通的范围,
相当于a(c)
 search3D 在三维体数据内搜索。


应用:给定步长,可实现半自动矢量化,
半自动跟踪一条线。
矩阵操作
A#B 表示 A的列乘以B的行
 A##B表示 A的行乘以B的列
 Transpose 矩阵转置 a[i,j] = a[j,i]
……

IDL 数据I/O

ASCII_TEMPLATE 和 READ_ASCII

BINARY_TEMPLATE 和 READ_BINARY

IDL LIVE_TOOLS

DIALOG_READ_IMAGE 和
DIALOG_WRITE_IMAGE
IDL程序结构
 主程序
 Procedure
 Function
 method
主程序(两种表现形式)

1、程序体
…
end
 文件名为test.pro,没有名称的主程序必
须放在程序最后面。
 源代码编译后,直接执行没有名称的放
在最后的主程序
主程序(两种表现形式)

pro test
程序体
…
end
 文件名为test.pro。
 源代码编译后,直接执行与文件名同名
的主程序
主程序(两种表现形式)
pro 程序名
程序体
end
主程序例程




For example, here is a main program that
plots ten random numbers. It is placed in a
file named pnums.pro.
numbers = randomu(seed, 10) * 20.0
plot, numbers
end
Execute this main program using the .RUN
executive command.
IDL> .run pnums
Procedure





结构:
pro 子程序名称,变量V1,V2, … ,k1=k1,k2=k2
程序体
end
keyword起重要作用
Procedure

The procedure is placed in the file
twoplot.pro.
pro twoplot, one, two
loadct, 5
plot, one, COLOR=125
oplot, two, COLOR=180
End
调用时:
IDL> twoplot, var1, var2
Function(函数)

Function test
变量 V1,V2, … ,
关键字 k1=k1,k2=k2

程序体
return, Value
end
Function(函数)

a file named mean.pro.
function mean, array
average =
total(array)/n_elements(array)
return, average
end
Call MEAN from the command line
and return its output to a named
variable:
 IDL> avgarray =

定义对象的
method

pro class_name:: test,变量V1,V2, …
,k1=k1,k2=k2
程序体
…
end
调用方法

调用routines:
– test, v1,v2,…,k1=k1,k2=k2, …
– keyword 可有可无,若没有,用缺省值。

调用Function:
– result=test(v1,v2, …,k1=k1,k2=k2, …)
调用方法
调用method:
 Object -> test, v1,v2…

IDL 程序条件语句
Begin – End
 If – Then – Else
 For – Do
 While – Do
 Repeat – Until
 Case X of – else – endcase
 Expr? Expr1:expr2 (条件判断语句)

界面设计

两种方式
– GUI方式
– 程序方式
程序方式创建界面
pro test ;主程序
base=widget_base(/column)
button1=widget_button(base,value='打开',uvalue='op')
draw=widget_draw(base,uvalue='dra',xsize=800,ysize=600);, $
;x_scroll_size=1000,y_scroll_size=1000)
button2=widget_button(base,value='退出',uvalue='ex')
widget_control,base,/realize
xmanager,'test',base;,event='test_event'
end
程序方式创建界面
pro test_event, ev ;事件处理程序
widget_control,ev.id, get_uvalue=uv
case uv of
'op':begin
shade_surf,dist(100)
end
'ex':begin
widget_control,ev.top,/destroy
end
endcase
end
IDL控件实例
PRO widget2 ;主程序
base = WIDGET_BASE(/COLUMN)
button1 = WIDGET_BUTTON(base, VALUE='One',
UVALUE='ONE')
button2 = WIDGET_BUTTON(base, VALUE='Two',
UVALUE='TWO')
text = WIDGET_TEXT(base, XSIZE=20)
button3 = WIDGET_BUTTON(base, value='Done',
UVALUE='DONE')
WIDGET_CONTROL, base, SET_UVALUE=text
WIDGET_CONTROL, base, /REALIZE
XMANAGER, 'Widget2', base
END
IDL控件实例
PRO widget2_event, ev ;事件处理程序
WIDGET_CONTROL, ev.top, GET_UVALUE=textwid
WIDGET_CONTROL, ev.id, GET_UVALUE=uval
CASE uval OF
'ONE' : WIDGET_CONTROL, textwid, SET_VALUE='Button
One Pressed'
'TWO' : WIDGET_CONTROL, textwid, SET_VALUE='Button
Two Pressed'
'DONE': WIDGET_CONTROL, ev.top, /DESTROY
ENDCASE
END
Color in IDL
8 bit Color — Color Lookup Tables(LUT)
 24 bit Color — 指定RGB颜色

– 在程序开始时将decomposed选相关掉

Device, decomposed=0
或:根据颜色深度指定颜色
察看系统颜色信息:
Device,get_visual_depth=vd
Sysdevinfo
Help,/device
浏览彩色表:cindex, xloadct
IDL Direct and Object Graphics
直接图形法和对象图形法
直接图形法: 创建2D图形时常用,如:
plot, mapping, contours. 简单、快速,但
需反复重画;
 对象图形法: 加速3D系统显示,灵活,交
互性强,充分控制对象,对象驻留内存,
不需反复重画。

Live Tools 对象编程
高效快捷的对象分析工具,提供如下函数:

Live_contour
 Live_control
 Live_destroy
 Live_export
 Live_Image
 Live_info
 Live_load

Live_oplot
 Live_plot
 Live_print
 Live_rect
 Live_surface
 Live_text
 Live_style
IDL定义对象
定义类的Structure
Structure={IDLexModelManip, $ INHERITS,
IDLgrModel, 常量及新的对象}

The following is an example of a structure definition procedure that defines a
structure that will be used for the class CNAME.
PRO CNAME__DEFINE
struct = { CNAME, data1:0L, data2:FLTARR(10) }
END
IDL定义对象

定义类的method:
PRO ClassName::Method
IDL statements
END
or
FUNCTION ClassName::Method, Argument1
IDL statements
RETURN, value
END
创建对象

Result = OBJ_NEW([ObjectClassName [, Arg1 ...Argn]])

如:a=obj_new(‘idlgrmodel’)
删除对象

OBJ_DESTROY, ObjRef [, Arg1, , Argn]
IDL中对象种类
四大类:
 容器:View, Window
 模型:idlgrmodel,是容器对象的子对象
起承上启下作用
 原子:image,surface,polyline,ploygon,光
源(均可直接显示)
 属性:符号,IDLgrFont,(无法直接显示)

IDL对象关系

四类对象呈树状关系
Graphics
Atom
Graphics
Atom
Model
Graphics
Atom
Model
View
Model
View
Scene

Graphics
Atom
一个只能有一个父对象
参数传递
调用 时传递
Surface,a,color=[255,0,0]
限制性强
 公共区传递
Common fd,a,b,c 公共区占用

PRO MULT, M
COMMON SHARE2, E, F, G
M=E*F*G
PRINT, M, E, F, G
RETURN
END
PRO DIV, D
COMMON SHARE2
D=E/F
PRINT, D, E, F, G
RETURN
固定内存
 用uservalue传递参数
 Keyword传递
IDL Pointer 指针
与C、C++中指针不同,只是IDL堆变量
的索引,不存在真正的内存地址。
 相关函数: PTR_NEW,
PTR_VALID,PTR_FREE
 调用方法:
a=findgen(10)
aptr=ptr_new(a)
Print,*aptr

IDL 坐标系统
Data 数据坐标
缺省的坐标系统,plot, contour, surface常用
 Device 设备坐标
以像素为单位的物理坐标,tv, tvscl常用
 Normal 归一化坐标,从0到1,对象图形
法常用

外部语言接口
Spawn 子进程
 Active X 控件
 RPC 远程进程调用
 Call_external
 Link_image
 Callable IDL

Spawn 子进程

Windows下可执行操作,无法返回信
息。
 Spawn,’cd/windows’
 单用spawn,可到dos操作系统下。
 Unix下,可以多进程使用,非常有用。
Active X 控件

Vb调用IDL
 界面由VB设计,触发事件可有
VB或IDL控制。
 控件初始化
 IDL程序初始化
RPC (Remote Procedure Calls)

只支持UNIX平台

allows IDL to be run as an RPC server and
your own program to be run as a client. IDL
commands can be sent from your
application to the IDL server, where they are
executed. Variable structures can be defined
in the client program and then sent to the
IDL server for creation as IDL variables.
Similarly, the values of variables in the IDL
server session can be retrieved into the
client process.
RPC (Remote Procedure Calls)


将IDL作为Server端
IDL命令环境
IDLDE 开发环境
在Server端运行IDL时
idlrpc -server=
server_number
将IDL作为Client端
IDL_VARIABLE 结构对变量作说明
IDL_RPCGetMainVariable
Linking to the Client Library, libidl.rfc.h
Call_external

通过目标码进行传递,可调用任何语言的
Code(如c和Fortran),适合任何操作平台。
X = FINDGEN(10)
S = CALL_EXTERNAL('example.so', $
'sum_array' X, N_ELEMENTS(X), /F_VALUE)
In this example, example.so is the name of the sharable image file,
sum_array is the name of the entry point, and X and N_ELEMENTS(X)
are passed to the called routine as parameters. The F_VALUE keyword
specifies that the returned value is a floating-point number rather than
an IDL_LONG.


缺点:数据在传递时数据大小和类型都必须已知,且
不能传递虚拟变量。
建议:写错误捕捉子程序。
Link_image
把外部程序变为内部程序
 须了解IDL的内部结构 IDL internals
 调用 n=link_image()
 传递变量
 Keyword的处理:Signals:捕捉,控制
 Unix操作系统允许多进程

Callable IDL


IDL can be called as a subroutine from other programs. This
capability is referred to as Callable IDL to distinguish it from the
more common case of calling your code from IDL via
CALL_EXTERNAL or LINKIMAGE.
IDL for Windows has a small driver program linked to a Dynamic
Link Library (DLL).
效率高
 与RPC接近(在RPC中,必须先启动IDLRPC
Server)
 比较复杂

IDL DataMiner

The IDL DataMiner is an Open Database
Connectivity (ODBC) interface that allows IDL
users to access and manipulate information from
a variety of database management systems.
Research Systems, Inc., developed IDL
DataMiner so that IDL users can have all the
connectivity advantages of ODBC without having
to understand the intricacies of ODBC or SQL
(Structured Query Language).
IDL DataMiner allow you:





Connect to a database
management system
(DBMS)
Query data from a
DBMS
Get information about
the available database
tables in a DBMS
Access a table in a
DBMS
Create a table in a
DBMS

Delete a table in a
DBMS
 Perform standard SQL
operations in the DBMS
 Get information about
the columns in a
selected table
 Add/Change/Delete
records in a table
IDL DataMiner
The IDL DataMiner provides two IDL
objects for accessing databases:
•Database object (IDLdbDatabase)
•Recordset object (IDLdbRecordset)

IDL DataMiner
status = DB_EXISTS()
 objDB =
OBJ_NEW('IDLdbDatabase')
 status =
DIALOG_DBCONNECT(objDB)


sources = objDB->GetDatasources()
IDLdbDatabase
myDB =
OBJ_NEW('IDLdbDatabase')
 OBJ_DESTORY, myDB

status = DIALOG_DBCONNECT(DBobj)
 status = DB_EXISTS()

IDLdbDatabase






IDLdbDatabase::Connect
IDLdbDatabase::ExecuteSQL
IDLdbDatabase::GetDatasources
IDLdbDatabase::GetProperty
IDLdbDatabase::GetTables
IDLdbDatabase::SetProperty
Connect ODBC for Oracle

Connect ODBC for Oracle supports two
separate drivers.
– Connect ODBC for Oracle 7(the Oracle driver) supports the
Oracle 7 database system.
– Connect ODBC for Oracle 8 (the Oracle 8 driver)supports
the Oracle 8 database system.
– The Oracle 8 driver is supported in the Windows 9x,
Windows NT,Macintosh Power PC, and UNIX environments.
– See the README file shipped with your INTERSOLV
DataDirect product for the file names of the Oracle drivers.
IDLdbRecordset
The IDLdbRecordset object contains a
database table or the results from an
SQLquery.
 RSObj = OBJ_NEW('IDLdbRecordset',
DBobj, KEYWORD)
 OBJ_DESTROY, RSObj

IDLdbRecordset









IDLdbRecordset::AddRecord
IDLdbRecordset::CurrentRecord
IDLdbRecordset::DeleteRecord
IDLdbRecordset::GetField
IDLdbRecordset::GetProperty
IDLdbRecordset::GetRecord
IDLdbRecordset::MoveCursor
IDLdbRecordset::NFields
IDLdbRecordset::SetField
网上相关资源

www.rsinc.com

www.dfanning.com

……
Questions?
谢 谢!