添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
idl中数组存储方式为按行优先存储,这是为了数据处理时候, 当数据量比较大的时候,不能一次读取全部数据,所以为了数据读取方便, 设置了按行读取这一个规定,所以内存中数据存储方式也是按行存储, 这一方式与通常所见的matlab,mathematica等矩阵操作语言有所不同。 idl中数组下标从0开始,这和c语言中数组下标索引方式是相同的, 但是和matlab,fortran等语言有所不同。

(一)语法基础

!p 直接图形法下绘图的基本设置参数 !x 直接图形法下绘制x坐标轴的参数 !y y坐标轴的参数 !z z坐标轴的参数 !d 当前图形显示输出设备信息 IDL> ;向下取整 IDL> floor ( 2.8 ) IDL> ;向上取整 IDL> ceil (- 1.8 ) IDL> ;四舍五入 IDL> round ( 2.5 ) IDL> round (- 2.5 ) IDL> !dpi 3.1415926535897931 IDL> !pi 3.1415927 IDL> arr = [[ 1 , 2 , 3 ],[ 4 , 5 , 6 ]] IDL> help ,arr ARR INT = Array[ 3 , 2 ] IDL> print ,arr 1 2 3 4 5 6 IDL> ;数组下标从0开始 IDL> ;idl中数组按行存储 IDL> arr[ 2 , 1 ] IDL> print , BytArr ( 3 , 3 ) 0 0 0 0 0 0 0 0 0 IDL> print , findgen ( 6 ) 0.000000 1.00000 2.00000 3.00000 4.00000 5.00000 IDL> make_array ( 2 , 2 ,/integer,/index) IDL> make_array ( 2 , 2 ,/integer,value = 8 ) IDL> arr = indgen ( 4 ) IDL> arr 0 1 2 3 IDL> print ,arr > 3 3 3 3 3 IDL> print ,arr < 2 0 1 2 2 IDL> print ,arr mod 2 0 1 0 1 IDL> otarr = [ 2 , 4 ] IDL> print , arr + otarr IDL> arr 0 1 2 3 IDL> ;数组运算和元素最少的数组个数一致 IDL> arr1 = [[ 1 , 2 , 3 ],[ 4 , 5 , 6 ]] IDL> arr2 = [[ 1 , 2 ],[ 3 , 4 ],[ 5 , 6 ]] IDL> arr1 1 2 3 4 5 6 IDL> arr2 IDL> arr1 + arr2 2 4 6 8 10 12 IDL> ;idl按行存储,运算过程不考虑维度,只考虑内存长度 IDL> ;数组合并 IDL> arr1 = [[ 1 , 2 ],[ 3 , 4 ]] IDL> arr2 = [[ 5 , 6 ],[ 7 , 8 ]] IDL> [arr1,arr2] 1 2 5 6 3 4 7 8 IDL> [[arr1],[arr2]] IDL> size (arr2) 2 2 2 2 4 IDL> arr2 IDL> ;依次对应 2维 1维上2个元素 2维上2个元素 整数型 共4个元素 IDL> size ([arr1,arr2]) 2 4 2 2 8 IDL> arr = indgen ( 6 ) IDL> arr 0 1 2 3 4 5 IDL> result = where (arr GT 3 ,count,complement = res_c,ncomplement = res_n) IDL> ;idl函数,在函数调用时,传入keywords可以返回对应参数值 IDL> ;符合arr GT 3 的元素个数 IDL> print , count IDL> print , result IDL> ;不符合arr GT 3的元素个数 IDL> print , res_n IDL> print , res_c 0 1 2 3 IDL> where (arr EQ 2 ) IDL> ;返回的是元素值为2的元素坐标 IDL> arr = indgen ( 3 , 2 ) IDL> reform (arr, 1 ) % REFORM : New subscripts must not change the number elements in ARR. % Execution halted at: $MAIN$ 1 C:\Users\Rdx\Documents\idl\guide\guide. pro IDL> reform (arr, 1 , 6 ) IDL> reform (arr, 6 , 1 ) 0 1 2 3 4 5 IDL> arr 0 1 2 3 4 5 IDL> reverse (arr, 1 ) 2 1 0 5 4 3 IDL> ;左右旋转 IDL> reverse (arr, 2 ) 3 4 5 0 1 2 IDL> ;上下旋转 IDL> transpose (arr) IDL> sort (arr) 0 1 2 3 4 5 IDL> arr 0 1 2 3 4 5 IDL> arr = [[ 2 , 4 , 1 ],[ 5 , 3 , 1 ]] IDL> sort (arr) 5 2 0 4 1 3 IDL> ;sort返回的是数组的下标索引 IDL> arr[ 4 ] IDL> arr( 4 ) IDL> ;数组元素个数 IDL> n_elements (arr) IDL> min (arr) IDL> max (arr) IDL> total (arr) 16.000000 IDL> total (arr[ 1 ,]) total (arr[ 1 ,]) % Syntax error. IDL> total (arr[ 1 ,*]) 7.0000000 IDL> arr 2 4 1 5 3 1 IDL> ;求积 IDL> product (arr) 120.00000000000000 IDL> product (arr[ 1 ,*]) 12.000000000000000 IDL> product (arr[ 1 , 3 , 4 ]) % Attempt to subscript ARR with <INT ( 3 )> is out of range. % Execution halted at: $MAIN$ 1 C:\Users\Rdx\Documents\idl\guide\guide. pro IDL> arr 2 4 1 5 3 1 IDL> ;累计积 IDL> product (arr,/cumulative) 2.0000000000000000 8.0000000000000000 8.0000000000000000 40.000000000000000 120.00000000000000 120.00000000000000 IDL> product (arr, 1 ) 8.0000000000000000 15.000000000000000 IDL> product (arr, 2 ) 10.000000000000000 12.000000000000000 1.0000000000000000 IDL> factorial ( 3 ) % Compiled module: FACTORIAL . 6.0000000000000000 IDL> mean (arr) 2.6666667 IDL> ;moment()函数计算数组的平均值、方差、倾斜度和频率曲线峰态 IDL> moment (arr) 2.6666667 2.6666667 0.21262917 - 1.8645834 IDL> arr1 = [ 1 , 2 , 3 ] IDL> arr2 = [[ 1 ],[ 2 ],[ 3 ]] IDL> arr1 1 2 3 IDL> arr2 IDL> arr1 # arr2 1 2 3 2 4 6 3 6 9 IDL> arr2 # arr1 IDL> ;正常的矩阵运算,行乘列 IDL> arr1 ## arr2 IDL> arr2 ## arr1 1 2 3 2 4 6 3 6 9 IDL> s1 = 'abcdef' IDL> s2 = strarr ( 3 ) IDL> s2[ 0 ] = 'ab' IDL> s2[ 1 ] = 'cd' IDL> s2 IDL> s2[ 3 ] = 'cd' % Attempt to subscript S2 with <INT ( 3 )> is out of range. % Execution halted at: $MAIN$ IDL> s1 + s2[ 1 ] abcdefcd IDL> ;+号实现字符串相加 IDL> ;strcmp 字符串比较 IDL> ;strlen 字符串长度 IDL> ;strmid(str,poslen) 从字符串pos开始取出len长度子串 IDL> s1 = 'abcdefg' IDL> strlen (s1) IDL> strpos (s1, 'c' ) IDL> strmid (s1, 2 ) cdefg IDL> s1 abcdefg IDL> strmid (s1, 2 , 5 ) cdefg IDL> s2 = ' a b ' IDL> strtrim (s2, 0 ) IDL> strtrim (s2, 1 ) IDL> strtrim (s2, 2 ) IDL> ;0表示删去尾部空格,1表示删去首部空格,2表示删去两边的空格