1.数组的创建
创建索引数组:findgen(num),dindgen(num)
创建一个特定纬度的数组并赋值:replicate(2.0,4,2),创建4列2行值为2.0的数组
2.数组的运算
标量乘;
#数组乘,将一个数组的列乘以另一个数组的行,和数学运算列行乘法不同
如:a=dindgen(3,2) , b=dindgen(2,3) , c=a#b=(3,3)
##矩阵乘
d=a##b=(2,2)
LMN=[[0.85,-0.50,-0.16],[0.50,0.87,-0.08],[0.17,-0.01, 0.98]]
C1=[7.53,-8.06, -2.31]
print,LMN##C1
3.语句
if 条件 then 语句
if 条件 then begin
语句
endif
if 条件 then
语句
endif else
语句
endelse
case 表达式 of
情况1:语句
情况2:语句
情况3:begin
语句
end
else: 语句
endcase
while 语句 do begin
语句
endwhile
goto,标号
label : 标号
4.画图系列
(1)日期格式输出标准:“%H:%I:%S%3” 21:36:58.125
(2)把Window作为输出,第一个plot中不要加/noerase,否则会全黑.
(3)特殊符号:在IDL-help里面搜索vecor fonts,点击special characters
;垂直号:!9x!3 ;平行号:!9#!3 ;•:!9.!3 ; ×:!9X!3
B的旋度:!9GX!3B μ:!7l!3
(4)画Y=3的一条横线;oplot,TT0,replicate(3,n_elements(TT0),1),thick=2,color=47,linestyle=2
(5)如果想让y轴的刻度不显示,用ytickformat=’(a1)’
(6)把图上的点用symbol显示出来
sym_color=‘blue’,sym_size=4,symbol=’+’,sym_thick=8
(7)scatterplot(x,y,sym_thick=5)
(8)pplot = PLOT([tt1[i],tt1[i+1]], [lln1[i],lln1[i+1]], RGB_TABLE=39,VERT_COLORS=bytscl(alog10(data[i]),min=mmin,max=mmax,top=254),/OVERPLOT,THICK=5)
(9)t2=text(xpos,ypos,str,/norm,FONT_SIZE=15,color=‘black’)
5.建立画图模版
WINDOW, 0, XSIZE=950, YSIZE=650, Xpos = 700, Ypos =0
DEVICE,DECOMPOSED=0
!P.MULTI = [0,1,600]
loadct,39
Panels=5
Posi = dblarr(4,Panels)
dy=0.85/Panels
for i=1, Panels do begin
Posi[#,i-1]= [0.2, 0.95-dyi , 0.85, 0.95-dy(i-1.)]
endfor
tidex=[’(a)’,’(b)’,’(c)’,’(d)’,’(e)’,’(f)’,’(g)’,’(h)’,’(i)’,’(j)’,’(k)’,’(l)’,’(m)’,’(n)’,’(o)’,’§’]
panel=0
plot,x,y,xrange=[0,2],yrange=[0,2], xtitle=’ ‘, ytitle=’ ', xstyle=1, ystyle=1, background=255, color=0,position=[0.1,0.1,0.9,0.9], /normal, /nodata, thick=2, xthick=2, ythick=2, charthick=2, charsize=2
xyouts, 0.08, posi[1,Panel]+(posi[3,Panel]-posi[1,Panel])3.6/4,tidex[panel], color = 0, /normal,charsize=2.0ratio, charthick=1.5*ratio
pson,filename=‘pfigure2.ps’,PAPER=‘A4’,margin=1.0,aspect=0.8,landscape=0
panel=0
plot,x,y,xrange=[0,2],yrange=[0,2], xtitle=’ ‘, ytitle=’ ‘, xstyle=1, ystyle=1, background=255, color=0,position=[0.1,0.1,0.9,0.9], /normal, /nodata, thick=2, xthick=2, ythick=2, charthick=2, charsize=2
xyouts, 0.08, posi[1,Panel]+(posi[3,Panel]-posi[1,Panel]) 3.6/4,tidex[panel], color = 0, /normal,charsize=2.0ratio, charthick=1.5ratio
psoff
##plot(XX,YY)##
aa=plot(TT0,Rc0,color=[0,0,0],thick=3,xthick=3,ythick=3,ytitle=‘Rc’,xtitle=‘Time’,ylog=1,dimension=[1000,800])
plot(TT0,rou0,color=[255,0,0],thick=3,overplot=1)
plot(TT0,kapa0,color=[0,0,255],thick=3,overplot=1)
aa.Save,‘C:\Users\Administrator\Desktop\AAA.png’
makepng,‘C:\Users\zhu\Desktop*’
6.图上点击画线
wset,1
wshow,1
color = 255
for n = 0, 1, 1 do begin
cursor,px,py,/up,/norm ;get the new position
hx = px
hy = py
print, n, px, py
if hx ge 0.1 and hx le 0.90 then begin
plots,[hx,hx],[0.1,0.9], color=color,/norm,/thick,lines=0
plots,[0.1,0.9],[hy,hy], color=color,/norm,/thick,lines=0
;所画的线的时间点的计算
time = btime+(etime -btime)*(px-0.1)/0.75
caldat,time, MM, DD, YYYY, HH, MI, SS
StrTime = string(YYYY, format= ‘(I4.4)’)+string(MM, format= ‘(I2.2)’) +string(DD, format= ‘(I2.2)’) +’.’+string(HH, format= ‘(I2.2)’) +string(MI, format= ‘(I2.2)’) +string(SS, format= ‘(I2.2)’)
print,strtime
endif
endfor
不同的线型:
dashed line表示短划线,如_ _ _ _
dotted line表示点虚线,如…
7.画箭头
arrow, 32.5,32.5, 32.5+(Byimf/2.0), 32.5+(Bzimf/2.0), thick=3, hsize=-0.5, /data
8.保存数据
file_name = ‘C:\Users\zhu\Desktop**.txt’
OPENU, outunit, file_name, /APPEND, /GET_LUN
printf, outunit, record0,record1,E1,format = ‘(01(a2," "),01(d15.6, " "),01(d8.2, " "))’
FREE_LUN, outunit
save, tt,rr, vv,bb, filename=‘H:\zhu’+strcompress(string(kk), /REMOVE_ALL)+’.sav’
restore ,‘H:\zhu’+strcompress(string(kk), /REMOVE_ALL)+’.sav’
9.生成模版
filename = ‘C:\Users\zhu\Desktop*.txt’
Template = ASCII_TEMPLATE(Filename)
save, Template, filename=‘C:\Users\zhu\Desktop*.sav’
restore, ‘C:\Users\zhu\Desktop*.sav’
Result = READ_ASCII(filename, TEMPLATE=Template)
data1 =Result.(0)
10.数据保存和调用.sav格式
save, data, filename=‘D:\work\var.sav’
restore,‘D:\work\var.sav’
11.释放IDL内存
CDF_CLOSE, Id
delvar, Q
http://blog.sina.com.cn/s/blog_a10150440102wsct.html
12.文件重命名
file_move,‘D:\alldata\poo.txt’,‘D:\alldata\poo1.txt’
13.逐行阅读某数据不规则的txt
file = DIALOG_PICKFILE(FILTER=’*.txt’)
OPENR, lun, file, /GET_LUN
; Read one line at a time, saving the result into array
array = ‘’
line = ‘’
WHILE NOT EOF(lun) DO BEGIN & $
READF, lun, line & $
array = [array, line] & $
ENDWHILE
; Close the file and free the file unit
FREE_LUN, lun
14.数据处理技巧
寻找数据中非有限值(nan,infinite)
A=[1,3,9,!values.f_nan,50,!values.f_nan,81]
A[where(~finite(A))]=-9999
print,A
result=where(A eq -1.0e31)
if result ne -1 then A[result]=!values.f_nan
求一个数列中的众数
a = [1,2,3,4,5,6,7,2,3,2]
his = histogram(a)
idx = where(his eq max(his))
print,a[idx[0]]
求一个矩阵的特征值和特征向量
A = [[ 5.0, 4.0, 0.0, -3.0], [ 4.0, 5.0, 0.0, -3.0], [ 0.0, 0.0, 5.0, -3.0],[-3.0, -3.0, -3.0, 5.0]]
eigenvalues = EIGENQL(A, EIGENVECTORS = evecs)
Print, eigenvalues, evecs
cov = IMSL_COVARIANCES(B)
values = IMSL_PRINC_COMP(cov,EIGENVECTORS= ev)
normal=ev[*,2]
print,normal
print,‘vec values:’,values
矩阵的求逆
matric_power(array,-1)
比上面这个更具有普适性的事奇异值分解
SVDC,A,W,U,V
WP1[i,i]=1/W[i]
WP2[i,i]=W[i]
A=U##WP2##transpose(V)
AX=B →X=V##WP1##transpose(U)##B
把数据变为字符串并去掉空格
B=strcompress(string(A),/remove_all)
提取字符串中的数组
str = ‘1.0 2.0 4.0’
out = float(STRSPLIT(str, /EXTRACT))
print,out[0]
print,out[1]
print,out[2]
IDL中产生随机数主要有RANDOMU和RANDOMN两个函数,分别生成均匀分布和正态分布的随机数,比如生成[15,25]范围内的随机数40个,并取整
print,15+fix(10*randomu(seed,40))
生成差值为5,1开头,6个元素的等差数列
print, indgen(6)*5+1
生成比值为3,2开头的等比数列
print, 3^indgen(6)*2
15.编译生成exe
(1)多个pro文件时,使用构建工程(项目)
项目名称、主过程pro名称、构建sav文件名要保持一致。
在工程上右键选择"构建项目"或"构建工程"即可生成sav文件。
控制台显示构建成功提示:
SAV文件 At: D:\IDLViewer\IDLViewer_UseEnvi\idlviewer_useenvi.sav
(2)发布exe文件
控制台输入如下命令发布exe文件。
make_rt, ‘IDLViewer_UseEnvi’, ‘D:\temp’, savefile=‘D:\IDLViewer\IDLViewer_UseEnvi\idlviewer_useenvi.sav’, /overwrite, /vm
注:上面代码为一条命令,不需要回车。
(3)修改ini文件
用记事本打开ini配置文件,show=True改成show=False可以取消虚拟机提示窗口
16.64位主程序中调用32位进程
new=idl_idlbridge(ops=32)
new->execute,‘read_inputfile_to_lkmiu,para=para,sixd0=sixd0,pan=pan,outhigh=outhigh,eneypas=eneypas’
para=new->getvar(‘para’)
sixd0=new->getvar(‘sixd0’)
pan=new->getvar(‘pan’)
outhigh=new->getvar(‘outhigh’)
eneypas=new->getvar(‘eneypas’)
17.程序中自动解压缩文件语句
spawn, ‘7z e D:\IDLprogram\model_engine\ele.rar -oD:\IDLprogram\model_engine\ rbspa_mageis_UKLdatabase_2014_1.sav -r -y’