IDL基础

先列后行

arr=indgen(3,4)
SIZE(arr,/dimensions)
 print ,where(arr gt7)
print,arr[where(arr gt 7)]
print,where(arr gt 7,cout,COMPLEMENT=com,ncomplement=ncom)
array[WHERE(array GT 5, /NULL)] = 5

arr=indgen(2,8);
arrReform=reform(arr,1,8);维数一定,改变个数
arrRebin=REBIN(arr,2,8);维数一定,改变每一维的倍数
 arrCongrid=congrid(arr,1,1)
arrRotate5=ROTATE(ARR,5)

arr=indgen(8)
print,arr[sort(arr)];sort()返回排序后的索引

print,uniq(arr,sort(arr));返回arr中的唯一值,即,不重复,如果用uniq(arr)则返回的是将相邻的相同值只取一个,不相邻的却去不了

print,arr1 # arr2;数组相乘
print,arr1 ## arr2;矩阵相乘

print,strmid(str,strlen(str)+1,strlen(str),/reverse_offset);反向截取字符串
file=dialog_pickfile()
print,file

hdr=STRMID(file,pointPosition+1,strlen(file)-pointPosition-1)

help,strtrim(string(a),1);转换为string并trim掉一边的空格


结构体
 str={v1:5,v2:'dfdf'};定义匿名结构体
print,n_tags(str);结构体个成员个数
print,tag_names(str);结构体成员 名称
print,str.v1;某一成员的值

str3={two,inherits one,v4:'1'};two结构体继承自one,并向two添加v4变量
动态扩展
str4=create_struct(str2,'v5',findgen(5));创建结构体,并将str2中的数据也copy过来

指针
data=indgen(5);定义数组
ptr=ptr_new(data);定义指针------ptr_new()
Data=!null;制空
print,*ptr;打印指针,-------*ptr
ptr=ptr_new(data,/no_copy);创建指针后将data制空(undefined)
print,*pt=5;动态赋值还可以动态改变
print,*pt=indgen(5)

链表
obj_destroy,list;销毁list
Obj_valid(list);结果如果为0则说明销毁对象list

逻辑运算符
&&与
||或
~非

位运算符
AND
NOT
OR
XOR异或
if (keyword_set(xxx)) then begin;keyword_set()方法用于判断是否输入xxx

关键字继承
Plotex.por文件
pro plotex,x,y,_extra=_extra
plot,x,y,_extra=_extra			;_strict_extra=_extra严格关键字继承
end
然后在控制台中键入
IDL> x=findgen(100)/10
IDL> plotex,x,sin(x)
IDL> plotex,x,sin(x),thick=2,color=255
效果如下
pro plotex,x,y,_ref_extra=_extra;_ref_extra定义之后plotex只接受下面_extra=[]中指定的变量
plot,x,y,_extra=['thick','color']
End

pro plotex,x,y,_strict_extra=_extra
plot,x,y,_extra=_extra	        ;_strict_extra=_extra严格关键字继承
end


算法优化

a=!null;结果:A               UNDEFINED = !NULL
delvar,a;结果:A               UNDEFINED = <Undefined>
IDL> a=4
IDL> b=5
IDL> c=temporary(a)+temporary(b)
IDL> help,c,a,b
C               INT       =        9
A               UNDEFINED = <Undefined>
B               UNDEFINED = <Undefined>
IDL> 

时间控制
TIC:程序开始
TOC:程序结束
EX:
pro plotex,x,y,_ref_extra=_extra
tic
plot,x,y,_extra=['thick','color']
toc
End
结果:% Time elapsed: 0.0069999695 seconds.
clip_image001
IDL> z=shift(dist(40),20,20)
% Compiled module: DIST.
IDL> z=exp(-(z/10)^2)
IDL> surface,z
IDL> 
输出为:
clip_image002
数据输入输出:
print,read,reads,string()
IDL> str='123 45 idl'
IDL> a=0
IDL> b=''
IDL> reads,str,a,b
IDL> help,a,b
A               INT       =      123
B               STRING    = ' 45 idl'

Format---输出格式控制
[n]FC[+][-][width]
Opner	只读操作
Openw	写文件
Openu	
File_search()	搜索特定的文件
Dialog_pickfile()	
Fstat()	
Eof()	判断是否到最后
Close	关闭逻辑设备号
Free_Lun	释放逻辑设备号
;按行读取数据
pro readAndWriteFile
file=dialog_pickfile();打开文件
openr,lun,file,/get_lun;读取文件
temp='';定义中间变量用来存储读取的数据
openw,lunOpen,'F:\envi\Temp\openw1.txt',/get_lun
while(~eof(lun))do begin
  readf,lun,temp
  printf,lunOpen,temp
Endwhile 
free_lun,lun
free_lun,lunOpen
end

;分块读取数据
file=dialog_pickfile()
openr,lun,file,/get_lun
data1=strarr(20)
data2=findgen(6,30)
readf,lun,data1
readf,lun,data2
print,data1
print,data2

;向导式读取数据
pro ascii_templatemethond
file=dialog_pickfile()
if ~file_test(file) then return 
template=ascii_template(file);存为二进制文件
if size(template,/type) eq 2 then return;判断读进来的数据是否为整形
data=read_ascii(file,template=template);读取二进制文件
p=plot(data.(1));用读到的数据的第二列制图
help,data
print,data.(0)
End

;规则数据读取
pro array
file=dialog_pickfile()
openr,lun,file,/get_lun
readf,lun,firstLine
colum=0
row=0
type=0
reads,firstLine,colum,row,type
arr=make_array(colum,row,type=type)
readf,lun,temp1
readf,lun,temp2
;忽略两行
readf,lun,temp3
print,temp3
end

二进制文件读取
Readu
writeu

风云数据读取
file=dialog_pickfile()
openr,lun,file,/get_lun
headline=intarr(3)
 point_lun,lun,20;跳过前面20个数据
readu,lun,headline
fyarr=bytarr(1201,1201)
point_lun,lun,2*1201;跳过两行
tvscl,fyarr

读图片
file=dialog_pickfile()
read_jpeg,file,data
tvscl,data,/true;true为1,从help data-->DATA            BYTE      = Array[3, 600, 400],3在第一个位置,
 write_jpeg,"桌面\1.jpg",tvrd(true=1),quality=75,true=1
posted @ 2015-01-30 17:52  上官瑾文  阅读(859)  评论(0编辑  收藏  举报