Ren Dexin
Space Science, ESS of USTC, China.
(一)语法基础
!p 直接图形法下绘图的基本设置参数 !x 直接图形法下绘制x坐标轴的参数 !y y坐标轴的参数 !z z坐标轴的参数 !d 当前图形显示输出设备信息 IDL> ;向下取整 IDL> floor(2.8) 2 IDL> ;向上取整 IDL> ceil(-1.8) -1 IDL> ;四舍五入 IDL> round(2.5) 3 IDL> round(-2.5) -3 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] 6 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) 0 1 2 3 IDL> make_array(2,2,/integer,value = 8) 8 8 8 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> IDL> otarr = [2,4] IDL> print, arr + otarr 2 5 IDL> arr 0 1 2 3 IDL> ;数组运算和元素最少的数组个数一致 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 1 2 3 4 5 6 IDL> arr1 + arr2 2 4 6 8 10 12 IDL> ;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]] 1 2 3 4 5 6 7 8 IDL> IDL> size(arr2) 2 2 2 2 4 IDL> arr2 5 6 7 8 IDL> ;依次对应 2维 1维上2个元素 2维上2个元素 整数型 共4个元素 IDL> size([arr1,arr2]) 2 4 2 2 8 IDL> 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> IDL> ;符合arr GT 3 的元素个数 IDL> print, count 2 IDL> print, result 4 5 IDL> ;不符合arr GT 3的元素个数 IDL> print, res_n 4 IDL> print, res_c 0 1 2 3 IDL> IDL> where(arr EQ 2) 2 IDL> ;返回的是元素值为2的元素坐标 IDL> 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) 0 1 2 3 4 5 IDL> reform(arr,6,1) 0 1 2 3 4 5 IDL> 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) 0 3 1 4 2 5 IDL> 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] 3 IDL> arr(4) 3 IDL> IDL> ;数组元素个数 IDL> n_elements(arr) 6 IDL> IDL> min(arr) 1 IDL> max(arr) 5 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> ;求积 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> 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> IDL> arr1 = [1,2,3] IDL> arr2 = [[1],[2],[3]] IDL> arr1 1 2 3 IDL> arr2 1 2 3 IDL> arr1 # arr2 1 2 3 2 4 6 3 6 9 IDL> arr2 # arr1 14 IDL> ;正常的矩阵运算,行乘列 IDL> arr1 ## arr2 14 IDL> arr2 ## arr1 1 2 3 2 4 6 3 6 9 IDL>字符串
IDL> s1 = 'abcdef' IDL> s2 = strarr(3) IDL> s2[0] = 'ab' IDL> s2[1] = 'cd' IDL> s2 ab cd 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) 7 IDL> strpos(s1,'c') 2 IDL> strmid(s1,2) cdefg IDL> s1 abcdefg IDL> strmid(s1,2,5) cdefg IDL> s2 = ' a b ' IDL> strtrim(s2,0) a b IDL> strtrim(s2,1) a b IDL> strtrim(s2,2) a b IDL> ;0表示删去尾部空格,1表示删去首部空格,2表示删去两边的空格 IDL>