Download presentation
Presentation is loading. Please wait.
1
The Interactive Data Language
交互式数据语言
2
功能简介 IDL是进行数据分析、可视化及跨平台应用开发的最佳选择。IDL集可视、交互分析、大型商业开发为一体,为您提供了最完善、最灵活最有效的开发环境。 (参考 idl5.5.ppt)
3
IDL培训提纲 对象图形 IDL简介及应用 对象操作 IDL程序特点 参数传递 命令行操作 与外部语言接口 数据输入输出 数据库接口
例程分析 回答问题 IDL简介及应用 IDL程序特点 命令行操作 数据输入输出 图像与信号处理 矩阵操作 界面设计
4
IDL程序特点 ——宽松的语法检查机制 分隔符为“,”,而非空格 不分大小写 变量无需事先说明
5
IDL符号 $ ;后面是注释 @ 批作业 如:@test 作为一行的第一个字符时,返回到操作系统下,如:$ dir
作为一行的最后一个字符时,相当于一行未写完,换行。 ;后面是注释 @ 批作业
6
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
7
变量命名规则 正确: reade6_$file only_8_bit ComputerType variables _day_of_year
错误: name.last third%file 4th_list $temp 变量名称长度不超过255个字符,但变量大小取决于计算机配置和 操作系统。
8
IDL变量类型 Type Len Creation Array Conversion Byte 1 A=5B Bytarr Integer
2 B=0;b=0S Intarr Fix Uint C=0U Uintarr unit Long 4 D=0L Lonarr Ulong E=0UL Ulonarr Long64 8 F=0LL Long64arr Ulong64 G=0ULL Ulon64arr Float H=0.0 Fltarr Double I=0.0D Dblarr Complex J=complex(1.0,0.0) Complexarr Dcomplex 16 K=dcomplex(1.0,0.0) Dcomplexarr String ? L=’hello’ Strarr Pointer M=ptr_new() Ptrarr --- Object N=obj_new() Objarr
9
IDL 变量 Scalar Array (1—8维) Structure(结构)
10
系统 Keyword 系统Keyword !dpi (3.1415926) !p 控制显示 如:!p.font, !p.color
!d (device,对设备进行控制) 如:device,get_screen_size=view 24bit显卡下显示8位假彩色图像,用 Device,decompose=0,(设置成8bit 256色)
11
矩阵操作 A=bytarr(512,512) 列 行 b=tan(a)+10 子区处理: A(*,1)表示第2行的所有列 A(*,1:10)
12
矩阵操作 若a为一二维数组,c=[10,15,20], 则A(c)将是一稀疏矩阵,只提取a中第10,15,20个元素,如可用来提取河流。
C=where(a,max=15,min=0) a( c)=255 将a中很暗的值变为255。 取字区还可实现非常多的局部操作。
13
WHERE 函数 Indices=where(data gt 0.4 and data lt 0.5) Data[indices]=1.0
14
矩阵操作 search2D 二维数组中在一定值域范围内以一初始点为准,搜索与它连通的范围,相当于a(c)
应用:给定步长,可实现半自动矢量化,半自动跟踪一条线。
15
矩阵操作 A#B 表示 A的列乘以B的行 A##B表示 A的行乘以B的列 Transpose 矩阵转置 a[i,j] = a[j,i] ……
16
IDL 数据I/O ASCII_TEMPLATE 和 READ_ASCII BINARY_TEMPLATE 和 READ_BINARY
IDL LIVE_TOOLS DIALOG_READ_IMAGE 和DIALOG_WRITE_IMAGE
17
IDL程序结构 主程序 Procedure Function method
18
主程序(两种表现形式) 1、程序体 end 文件名为test.pro,没有名称的主程序必须放在程序最后面。
… end 文件名为test.pro,没有名称的主程序必须放在程序最后面。 源代码编译后,直接执行没有名称的放在最后的主程序
19
主程序(两种表现形式) pro test 程序体 … end 文件名为test.pro。 源代码编译后,直接执行与文件名同名的主程序
20
主程序(两种表现形式) pro 程序名 程序体 end
21
主程序例程 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
22
Procedure 结构: pro 子程序名称,变量V1,V2, … ,k1=k1,k2=k2 程序体 end keyword起重要作用
23
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
24
Function(函数) Function test 变量 V1,V2, … , return, Value end
关键字 k1=k1,k2=k2 程序体 return, Value end
25
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 = mean(findgen(10))
26
定义对象的method pro class_name:: test,变量V1,V2, … ,k1=k1,k2=k2 程序体 … end
27
调用方法 调用routines: 调用Function: test, v1,v2,…,k1=k1,k2=k2, …
keyword 可有可无,若没有,用缺省值。 调用Function: result=test(v1,v2, …,k1=k1,k2=k2, …)
28
调用方法 调用method: Object -> test, v1,v2…
29
IDL 程序条件语句 Begin – End If – Then – Else For – Do While – Do
Repeat – Until Case X of – else – endcase Expr? Expr1:expr2 (条件判断语句)
30
界面设计 两种方式 GUI方式 程序方式
31
程序方式创建界面 pro test ;主程序 base=widget_base(/column) end
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
32
程序方式创建界面 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 endcase
33
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
34
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
35
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
36
IDL Direct and Object Graphics直接图形法和对象图形法
直接图形法: 创建2D图形时常用,如:plot, mapping, contours. 简单、快速,但需反复重画; 对象图形法: 加速3D系统显示,灵活,交互性强,充分控制对象,对象驻留内存,不需反复重画。
37
Live Tools 对象编程 Live_contour Live_oplot Live_control Live_plot
高效快捷的对象分析工具,提供如下函数: 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
38
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
39
IDL定义对象 定义类的method: PRO ClassName::Method IDL statements END or
FUNCTION ClassName::Method, Argument1 RETURN, value
40
创建对象 Result = OBJ_NEW([ObjectClassName [, Arg1 ...Argn]])
如:a=obj_new(‘idlgrmodel’)
41
删除对象 OBJ_DESTROY, ObjRef [, Arg1, , Argn]
42
IDL中对象种类 四大类: 容器:View, Window 模型:idlgrmodel,是容器对象的子对象 起承上启下作用
原子:image,surface,polyline,ploygon,光源(均可直接显示) 属性:符号,IDLgrFont,(无法直接显示)
43
IDL对象关系 四类对象呈树状关系 一个只能有一个父对象 Model Model Model View View Scene
Graphics Atom Graphics Atom Graphics Atom Graphics Atom Model Model Model View View Scene
44
参数传递 调用 时传递 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 固定内存 用uservalue传递参数 Keyword传递
45
IDL Pointer 指针 与C、C++中指针不同,只是IDL堆变量的索引,不存在真正的内存地址。
相关函数: PTR_NEW, PTR_VALID,PTR_FREE 调用方法: a=findgen(10) aptr=ptr_new(a) Print,*aptr
46
IDL 坐标系统 Data 数据坐标 缺省的坐标系统,plot, contour, surface常用 Device 设备坐标
以像素为单位的物理坐标,tv, tvscl常用 Normal 归一化坐标,从0到1,对象图形法常用
47
外部语言接口 Spawn 子进程 Active X 控件 RPC 远程进程调用 Call_external Link_image
Callable IDL
48
Spawn 子进程 Windows下可执行操作,无法返回信息。 Spawn,’cd/windows’ 单用spawn,可到dos操作系统下。
Unix下,可以多进程使用,非常有用。
49
Active X 控件 Vb调用IDL 界面由VB设计,触发事件可有VB或IDL控制。 控件初始化 IDL程序初始化
50
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.
51
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
52
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. 缺点:数据在传递时数据大小和类型都必须已知,且不能传递虚拟变量。 建议:写错误捕捉子程序。
53
Link_image 把外部程序变为内部程序 须了解IDL的内部结构 IDL internals 调用 n=link_image()
传递变量 Keyword的处理:Signals:捕捉,控制 Unix操作系统允许多进程
54
Callable IDL 效率高 与RPC接近(在RPC中,必须先启动IDLRPC Server) 比较复杂
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) 比较复杂
55
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).
56
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
57
IDL DataMiner The IDL DataMiner provides two IDL objects for accessing databases: Database object (IDLdbDatabase) Recordset object (IDLdbRecordset)
58
IDL DataMiner status = DB_EXISTS() objDB = OBJ_NEW('IDLdbDatabase')
status = DIALOG_DBCONNECT(objDB) sources = objDB->GetDatasources()
59
IDLdbDatabase myDB = OBJ_NEW('IDLdbDatabase') OBJ_DESTORY, myDB
status = DIALOG_DBCONNECT(DBobj) status = DB_EXISTS()
60
IDLdbDatabase IDLdbDatabase::Connect IDLdbDatabase::ExecuteSQL
IDLdbDatabase::GetDatasources IDLdbDatabase::GetProperty IDLdbDatabase::GetTables IDLdbDatabase::SetProperty
61
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.
62
IDLdbRecordset The IDLdbRecordset object contains a database table or the results from an SQLquery. RSObj = OBJ_NEW('IDLdbRecordset', DBobj, KEYWORD) OBJ_DESTROY, RSObj
63
IDLdbRecordset IDLdbRecordset::AddRecord IDLdbRecordset::CurrentRecord
IDLdbRecordset::DeleteRecord IDLdbRecordset::GetField IDLdbRecordset::GetProperty IDLdbRecordset::GetRecord IDLdbRecordset::MoveCursor IDLdbRecordset::NFields IDLdbRecordset::SetField
64
网上相关资源 … …
65
Questions? 谢 谢!
Similar presentations