the interactive data language 交互式数据语言. 功能简介 idl 是进行数据分析、...

Post on 20-Dec-2015

301 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

The Interactive Data Language交互式数据语言

功能简介

IDL 是进行数据分析、可视化及跨平台应用开发的最佳选择。 IDL集可视、交互分析、大型商业开发为一体,为您提供了最完善、最灵活最有效的开发环境。

( 参考 idl5.5.ppt)

IDLIDL 培训提纲培训提纲IDL 简介及应用IDL 程序特点命令行操作数据输入输出图像与信号处理矩阵操作界面设计

对象图形对象操作参数传递与外部语言接口数据库接口例程分析回答问题

IDLIDL 程序特点程序特点

分隔符为“ ,” ,而非空格不分大小写变量无需事先说明

—— 宽松的语法检查机制

IDLIDL 符号符号$

– 作为一行的第一个字符时,返回到操作系统下,如: $ dir

– 作为一行的最后一个字符时,相当于一行未写完,换行。

;后面是注释@ 批作业 如: @test

IDLIDL 命令行命令行 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 个字符,但变量大小取决于计算机配置和操作系统。

Type Len Creation Array ConversionByte 1 A=5B Bytarr ByteInteger 2 B=0;b=0S Intarr FixUint 2 C=0U Uintarr unitLong 4 D=0L Lonarr LongUlong 4 E=0UL Ulonarr UlongLong64 8 F=0LL Long64arr Long64Ulong64 8 G=0ULL Ulon64arr Ulong64Float 4 H=0.0 Fltarr FloatDouble 8 I=0.0D Dblarr DoubleComplex 8 J=complex(1.0,0.0) Complexarr ComplexDcomplex 16 K=dcomplex(1.0,0.

0)Dcomplexarr

DcomplexString ? L=’hello’ Strarr StringPointer 4 M=ptr_new() Ptrarr ---Object 4 N=obj_new() Objarr ---

IDL 变量类型

IDL IDL 变量变量ScalarArray (1—8 维 )Structure( 结构 )

系统 系统 Keyword 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 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 IDL 数据数据 I/OI/O

ASCII_TEMPLATE 和 READ_ASCII

BINARY_TEMPLATE 和 READ_BINARY

IDL LIVE_TOOLS

DIALOG_READ_IMAGE 和DIALOG_WRITE_IMAGE

IDLIDL 程序结构程序结构主程序ProcedureFunctionmethod

主程序(两种表现形式)主程序(两种表现形式)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.0plot, numbersend

Execute this main program using the .RUN executive command.

IDL> .run pnums

ProcedureProcedure

结构: pro 子程序名称,变量 V1,V2, … ,k1=k1,k2=k2

程序体

end keyword 起重要作用

ProcedureProcedure

The procedure is placed in the file twoplot.pro.

pro twoplot, one, twoloadct, 5plot, one, COLOR=125oplot, two, COLOR=180End调用时 :IDL> twoplot, var1, var2

FunctionFunction ((函数)函数)

Function test 变量 V1,V2, … , 关键字 k1=k1,k2=k2

程序体

return, Valueend

FunctionFunction ((函数)函数)a file named mean.pro.

function mean, arrayaverage = total(array)/n_elements(array)return, averageend

Call MEAN from the command line and return its output to a named variable:

IDL> avgarray = mean(findgen(10))

定义对象的定义对象的methodmethod

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 IDL 程序条件语句程序条件语句Begin – EndIf – Then – ElseFor – DoWhile – DoRepeat – UntilCase X of – else – endcaseExpr? 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=uvcase uv of'op':begin

shade_surf,dist(100)end'ex':begin

widget_control,ev.top,/destroyend

endcaseend

IDLIDL 控件实例控件实例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=textWIDGET_CONTROL, base, /REALIZEXMANAGER, 'Widget2', baseEND

IDLIDL 控件实例控件实例

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 ENDCASEEND

Color in IDLColor in IDL

8 bit Color — Color Lookup Tables(LUT) 24 bit Color — 指定 RGB 颜色

– 在程序开始时将 decomposed 选相关掉 Device, decomposed=0

或:根据颜色深度指定颜色

察看系统颜色信息:Device,get_visual_depth=vdSysdevinfoHelp,/device浏览彩色表: cindex, xloadct

IDL Direct and Object GraphicsIDL Direct and Object Graphics直接图形法和对象图形法 直接图形法和对象图形法

直接图形法 : 创建 2D 图形时常用,如:plot, mapping, contours. 简单、快速,但需反复重画;

对象图形法 : 加速 3D 系统显示,灵活,交互性强,充分控制对象,对象驻留内存,不需反复重画。

Live Tools Live Tools 对象编程对象编程Live_contourLive_controlLive_destroyLive_exportLive_ImageLive_infoLive_load

Live_oplotLive_plotLive_printLive_rectLive_surfaceLive_textLive_style

高效快捷的对象分析工具,提供如下函数:

IDLIDL 定义对象定义对象 定义类的 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

IDLIDL 定义对象定义对象 定义类的 method:PRO ClassName::Method IDL statementsEND

or FUNCTION ClassName::Method, Argument1 IDL statementsRETURN, valueEND

创建对象创建对象 Result = OBJ_NEW([ObjectClassName [, Arg1 ...Argn]])

如: a=obj_new(‘idlgrmodel’)

删除对象删除对象 OBJ_DESTROY, ObjRef [, Arg1, , Argn]

IDLIDL 中对象种中对象种类类

四大类:容器: View, Window模型: idlgrmodel, 是容器对象的子对象

起承上启下作用原子: image,surface,polyline,ploygon,光源(均可直接显示)

属性:符号, IDLgrFont,( 无法直接显示)

IDLIDL 对象关对象关系系

四类对象呈树状关系

一个只能有一个父对象

Graphics Atom

Model

View

Scene

Graphics Atom

Graphics Atom

Graphics Atom

Model Model

View

调用 时传递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 RETURNENDPRO DIV, D COMMON SHARE2 D = E / F PRINT, D, E, F, G RETURN

固定内存 用 uservalue 传递参数 Keyword 传递

参数传递

IDL Pointer IDL Pointer 指针指针与 C 、 C++ 中指针不同,只是 IDL堆变

量的索引,不存在真正的内存地址。相关函数 : PTR_NEW,

PTR_VALID,PTR_FREE调用方法 :

a=findgen(10)aptr=ptr_new(a)Print,*aptr

IDL IDL 坐标系统坐标系统Data 数据坐标缺省的坐标系统, plot, contour, surface 常

用Device 设备坐标以像素为单位的物理坐标, tv, tvscl 常用Normal 归一化坐标,从 0 到 1 ,对象图

形法常用

外部语言接口外部语言接口Spawn 子进程Active X 控件RPC 远程进程调用Call_externalLink_imageCallable IDL

Spawn Spawn 子进程子进程Windows 下可执行操作,无法返回信

息。Spawn,’cd/windows’单用 spawn, 可到 dos 操作系统下。Unix 下,可以多进程使用,非常有用。

Active X Active X 控件控件Vb 调用 IDL界面由 VB 设计,触发事件可有

VB 或 IDL 控制。控件初始化IDL 程序初始化

RPC (Remote Procedure RPC (Remote Procedure Calls)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 RPC (Remote Procedure Calls)Calls)

将 IDL 作为 Server端 IDL 命令环境

IDLDE 开发环境在 Server端运行 IDL 时

idlrpc -server= server_number

将 IDL 作为 Client端IDL_VARIABLE 结构对变量作说明IDL_RPCGetMainVariableLinking to the Client Library, libidl.rfc.h

Call_externalCall_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_imageLink_image

把外部程序变为内部程序须了解 IDL 的内部结构 IDL internals调用 n=link_image()传递变量Keyword 的处理: Signals:捕捉,控制Unix 操作系统允许多进程

Callable IDLCallable 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 DataMinerIDL 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: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 DataMinerIDL DataMiner

The IDL DataMiner provides two IDL objects for accessing databases:

Database object (IDLdbDatabase)� Recordset object (IDLdbRecordset)�

IDL DataMinerIDL DataMiner

status = DB_EXISTS()objDB = OBJ_NEW('IDLdbDatabase')

status = DIALOG_DBCONNECT(objDB)

sources = objDB->GetDatasources()

IDLdbDatabaseIDLdbDatabase

myDB = OBJ_NEW('IDLdbDatabase')

OBJ_DESTORY, myDBstatus =

DIALOG_DBCONNECT(DBobj)status = DB_EXISTS()

IDLdbDatabaseIDLdbDatabase

IDLdbDatabase::Connect IDLdbDatabase::ExecuteSQL IDLdbDatabase::GetDatasources IDLdbDatabase::GetProperty IDLdbDatabase::GetTables IDLdbDatabase::SetProperty

Connect ODBC for Connect ODBC for OracleOracle

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.

IDLdbRecordsetIDLdbRecordset

The IDLdbRecordset object contains a database table or the results from an SQLquery.

RSObj = OBJ_NEW('IDLdbRecordset', DBobj, KEYWORD)

OBJ_DESTROY, RSObj

IDLdbRecordsetIDLdbRecordset 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? Questions?

谢 谢!

top related