1. 程式人生 > >喚起那些年你對IDL的記憶(一)

喚起那些年你對IDL的記憶(一)

僅做複習參考用:本文整理參考了IDL-Help跟董彥卿老師編寫的教材

基礎

常用的命令及快捷鍵

輸出:print
檢視:help
續行符:$
同行符:&
註釋符: ;
常用快捷鍵:
這裡寫圖片描述
圖1 快捷鍵

語法

資料型別


IDL有17中基本資料型別,如下圖所示:
這裡寫圖片描述
圖2 資料型別

Size (源:IDL-help)


**description:**The SIZE function returns size and type information for its argument if no keywords are set. If a keyword is set, SIZE returns the specified quantity.
Examples

Print the size information for a 10 by 20 floating-point array by entering:
PRINT, SIZE(FINDGEN(10, 20))
IDL prints:
2 10 20 4 200 (1、維數 2、各位數的大小 3、型別Code 4、元素數)
This IDL output indicates the array has 2 dimensions, equal to 10 and 20, a type code of 4, and 200 elements total. Similarly, to print only the number of dimensions of the same array:

PRINT, SIZE(FINDGEN(10, 20), /N_DIMENSIONS)
IDL prints:
2
For more information on using SIZE, see the Additional Examples.
Syntax


Result = SIZE( Expression [, /L64] [, /DIMENSIONS | , /FILE_LUN | , /FILE_OFFSET | , /N_DIMENSIONS | , /N_ELEMENTS | , /SNAME, | , /STRUCTURE | , /TNAME | , /TYPE] )
Return Value
If no keywords are set, SIZE returns a vector of integer type. The first element is equal to the number of dimensions of Expression. This value is zero if Expression is scalar or undefined. The next elements contain the size of each dimension, one element per dimension (none if Expression is scalar or undefined). After the dimension sizes, the last two elements contain the type code (zero if undefined) and the number of elements in Expression, respectively. The type codes are listed below.
If a keyword is set, SIZE returns the specified information.
Note: The SIZE function treats lists and hashes as if they are one-dimensional arrays.

IDL Type Codes and Names
The following table lists the IDL type codes and type names returned by the SIZE function:
這裡寫圖片描述
圖3 Type Codes and Names

變數與常量

變數分為:區域性變數和系統變數
1、命名規則
變數長度:不能超過255個字元
首位:字母或下劃線
中後部:字母、下劃線、$
2、IDL_Validname (源:IDL-Help)
檢查變數名
The IDL_VALIDNAME function determines whether a string may be used as a valid IDL variable name or structure tag name. Optionally, the routine can convert non-valid characters into underscores, returning a valid name string.
Example
這裡寫圖片描述
圖4 IDL_Validaname

CONVERT_ALL
If this keyword is set, then each element of String is converted into a valid IDL variable name using the following rules:
All non-alphanumeric characters (except “_”, “!” and “$”) are converted to underscores

If the first character is a number or a “$”,then an underscore is prepended to the string
If the first character is not a valid character (“_”, “!”, “A”…“Z”) then that character is converted to an underscore
If the element of String is an empty string or a reserved word (such as “AND”) then an underscore is prepended to the string

Tip: The CONVERT_ALL keyword guarantees that a valid variable name is returned. It is useful in converting user-supplied strings into valid IDL variable names.

CONVERT_SPACES
If this keyword is set, then all spaces within each element of String are converted to underscores. If an element of String contains any other non-alphanumeric characters, then an empty string is returned, indicating that the string cannot be used as a valid variable name.

Note: CONVERT_SPACES behaves the same as CREATE_STRUCT when checking structure tag
3、N_Elements函式
判斷變數是否已經被定義,如果定義返回1,否則返回0.
4、型別轉換
這裡寫圖片描述
圖5 型別轉換函式
5、改變陣列部分元素不改變陣列資料型別
6、系統變數
分為預定義系統變數和自定義系統變數
預定義系統變數:常數變數、圖形變數、系統配置、錯誤處理

這裡寫圖片描述
圖6 常數變數
這裡寫圖片描述
圖7 影象變數
這裡寫圖片描述
這裡寫圖片描述
圖8 系統配置
這裡寫圖片描述
圖9 錯誤處理
自定義系統變數格式:Defsysv,變數名,變數值
注:自定義系統變數建立成功後,只可以修改,但是型別不變,生命週期從初始化成功到IDL程序關閉。

陣列

陣列是IDL中最重要的資料組織形式,支援0~8維,下標順序先列標、後行標。
1、陣列建立函式
這裡寫圖片描述
圖10 陣列建立函式
2、建立特定型別或數值的陣列
MAKE_ARRAY
The MAKE_ARRAY function enables you to dynamically create an array whose characteristics are not known until run time.

Examples
To create a 3-element by 4-element integer array with each element set to the value 5, enter:
M = MAKE_ARRAY(3, 4, /INTEGER, VALUE = 5)
Syntax
Result = MAKE_ARRAY ( [D1[, …, D8]] [, DIMENSION=vector] [, INCREMENT=value] [, /INDEX] [, /NOZERO] [, SIZE=vector] [, START=value] [, TYPE=type_code] [, VALUE=value] [, /BYTE | , /COMPLEX | , /DCOMPLEX | , /DOUBLE | , /FLOAT | , /INTEGER | , /L64 | , /LONG | , /OBJ, | , /PTR | , /STRING | , /UINT | , /UL64 | , /ULONG] )
3、儲存陣列
按行儲存
4、使用陣列
@1、下標方式

IDL> arr=indgen(8)
IDL> print,arr
       0       1       2       3       4       5       6       7
IDL> print,arr[4]
       4

注:8.0之後下標可以為負,-1代表最後一個元素。*

IDL> print,arr[-1]
       7
IDL> print,arr[-5:-1]
       3       4       5       6       7

@2、向量方式
讀取第1、2、4、5元素值

IDL> print,arr
       0       1       2       3       4       5       6       7
IDL> index=[0,1,3,4]
IDL> result=arr[index]
IDL> print,result
       0       1       3       4

5、陣列運算
@1、求大求小和求餘
注:求大、求小時會將陣列不符合的元素全都改變成比較的數值

IDL> print,arr
       0       1       2       3       4       5       6       7
IDL> print,arr>4
       4       4       4       4       4       5       6       7
IDL> print,arr<6
       0       1       2       3       4       5       6       6
IDL> print,arr mod 3
       0       1       2       0       1       2       0       1

@2、陣列與數的運算
每個元素與數進行運算

IDL> print,arr
       0       1       2       3       4       5       6       7
IDL> result=arr*2
IDL> print,result
       0       2       4       6       8      10      12      14
IDL> print,arr+3
       3       4       5       6       7       8       9      10

@3、陣列與陣列運算
結果元素個數與參與運算陣列最少元素個數的陣列一致,陣列元素運算按照行優先順序依次進行運算。

IDL> arr1=indgen(3,2)
IDL> print,arr1
       0       1       2
       3       4       5
IDL> arr2=indgen(3,2)*2
IDL> print,arr2
       0       2       4
       6       8      10
IDL> arr3=indgen(2,3)
IDL> print,arr3
       0       1
       2       3
       4       5
IDL> result=arr1+arr2
IDL> print,result
       0       3       6
       9      12      15
IDL> print,arr1+arr3
       0       2       4
       6       8      10
IDL> arr4=indgen(4)
IDL> print,arr1+arr4
       0       2       4       6

@4、數組合並
數組合並要求:兩個陣列行數或者列數相同。
注:列數相同合併寫法方式

行數相同:
IDL> print,arr1
       0       1       2
       3       4       5
IDL> print,arr4
       0       1       2       3
IDL> arr5=[arr1,arr4]
% Unable to concatenate variables because the dimensions do not agree: ARR4.
% Execution halted at: FIRST               4 F:\學習資料\IDL\code\Default\first.pro
%                      $MAIN$          
IDL> arr6=indgen(4,2)*3
IDL> print,arr6
       0       3       6       9
      12      15      18      21
IDL> arry5=[arr1,arr6]
IDL> print,arry5
       0       1       2       0       3       6       9
       3       4       5      12      15      18      21
列數相同:
IDL> print,arr1
       0       1       2
       3       4       5
IDL> print,arr7
       0       1       2
       3       4       5
       6       7       8
       9      10      11
IDL> result=[arr1,arr7]
% Unable to concatenate variables because the dimensions do not agree: ARR7.
% Execution halted at: FIRST               4 F:\學習資料\IDL\code\Default\first.pro
%                      $MAIN$          
IDL> result=[[arr1,arr7]]
% Unable to concatenate variables because the dimensions do not agree: ARR7.
% Execution halted at: FIRST               4 F:\學習資料\IDL\code\Default\first.pro
%                      $MAIN$          
IDL> result=[[arr1],[arr7]]
IDL> print,result
       0       1       2
       3       4       5
       0       1       2
       3       4       5
       6       7       8
       9      10      11

6、陣列相關函式
@1、條件查詢–WHERE(源IDL-Help)
The WHERE function returns a vector that contains the one-dimensional subscripts of the nonzero elements of Array_Expression. The length of the resulting vector is equal to the number of nonzero elements in Array_Expression. Frequently the result of WHERE is used as a vector subscript to select elements of an array using given criteria.

Note: When WHERE Returns –1
If the NULL keyword is not set, and all the elements of Array_Expression are zero, then WHERE returns a scalar integer with a value of –1. If you use this result as an index into another array without checking for –1 first, then this will return the last element of the array. To avoid this problem, you should either use /NULL or check the Count argument before indexing. For example:

; Use /NULL, if no elements match then array will not be modified:
array[WHERE(array GT 5, /NULL)] = 5
or,

; Use Count to get the number of nonzero elements:
index = WHERE(array GT 5, count)
; Only subscript the array if it is safe:
IF count NE 0 THEN array[index] = 5
Syntax
Result = WHERE( Array_Expression [, Count] [, COMPLEMENT=variable] [, /L64] [, NCOMPLEMENT=variable] [, /NULL] )

IDL> print,arr
       0       1       2       3       4       5       6       7
IDL> result=where(arr gt 3)
IDL> result1=where(arr lt 4)
IDL> result2=where(arr eq 5)
IDL> result3=where(arr ge 3)
IDL> result4=where(arr le 6)
IDL> print,result,result1,result2,result3,result4
           4           5           6           7
           0           1           2           3
           5
           3           4           5           6           7
           0           1           2           3           4           5           6

@2、調整大小–Reform()、Rebin()、Congrid()、Interpolate()函式
#1、Reform()
The REFORM function changes the dimensions of an array without changing the total number of elements.

修改維數,陣列元素大小不變

Examples
REFORM can be used to remove “degenerate” leading dimensions of size one. Such dimensions can appear when a subarray is extracted from an array with more dimensions. For example

; a is a 3-dimensional array:

a = INTARR(10,10,10)

; Extract a "slice" from a:
b = a[5,*,*]

; Use HELP to show what REFORM does:
HELP, b, REFORM(b)
Executing the above statements produces the output:
B            INT = Array[1, 10, 10]
<Expression> INT = Array[10, 10]

The statements have the identical effect. They create a new array, b, with dimensions of (200, 5), from a.:

b = REFORM(a,200,5)
b = REFORM(a,[200,5])

Syntax
Result = REFORM( Array, D1[, …, D8] [, /OVERWRITE] )
OVERWRITE:
Set this keyword to cause the specified dimensions to overwrite the present dimensions of the Array parameter. No data are copied, only the internal array descriptor is changed. The result of the function, in this case, is the Array parameter with its newly-modified dimensions. For example, to change the dimensions of the variable a, without moving data, enter:
a = REFORM(a, n1, n2, /OVERWRITE)
#2、Rebin()
The REBIN function resizes a vector or array to dimensions given by the parameters Di. The supplied dimensions must be integral multiples or factors of the original dimension. The expansion or compression of each dimension is independent of the others, so that each dimension can be expanded or compressed by a different value.

If the dimensions of the desired result are not integer multiples of the original dimensions, use the CONGRID function.
修改陣列大小,修改後陣列行或列數必須是原陣列行列數的整數倍,預設抽樣演算法是雙線性內插

IDL> print,arr2
       0       2       4
       6       8      10
IDL> result=rebin(arr2,6,4)
IDL> print,result
       0       1       2       3       4       4
       3       4       5       6       7       7
       6       7       8       9      10      10
       6       7       8       9      10      10
IDL> result=rebin(arr2,6,4,/sample)
IDL>;sample:最近鄰抽樣演算法
IDL> print,result
       0       0       2       2       4       4
       0       0       2       2       4       4
       6       6       8       8      10      10
       6       6       8       8      10      10

#3、Congrid()
The CONGRID function shrinks or expands the size of an array by an arbitrary amount. CONGRID is similar to REBIN in that it can resize a one, two, or three dimensional array, but where REBIN requires that the new array size must be an integer multiple of the original size, CONGRID will resize an array to any arbitrary size. (REBIN is somewhat faster, however.) REBIN averages multiple points when shrinking an array, while CONGRID just resamples the array.
**可以將陣列調整為同維任意大小。
處理一維、二維陣列時,預設演算法是最近鄰重取樣;
處理三維陣列時,預設採用雙線性內插演算法;
在對陣列進行縮小操作時,採用Rebin()函式進行插值處理,Congrid()函式僅進行重取樣。

Syntax
Result = CONGRID( Array, X, Y, Z [, /CENTER] [, CUBIC=value{-1 to 0}] [, /INTERP] [, /MINUS_ONE] )

IDL>;預設採用最近鄰重取樣演算法
IDL> print,arr2
       0       2       4
       6       8      10    
IDL> print,congrid(arr2,4,5)
       0       2       4       4
       0       2       4       4
       0       2       4       4
       6       8      10      10
       6       8      10      10

#4、Interpolate()
The INTERPOLATE function returns an array of linear, bilinear or trilinear interpolates, depending on the dimensions of the input array P.

Interpolates outside the bounds of P can be set to a user-specified value by using the MISSING keyword.
Examples
The example below computes bilinear interpolates with the keyword GRID set:

p = FINDGEN(4,4)

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5], [.5, 1.5, 2.5], /GRID)
and prints the 3 by 3 array:

2.50000 3.50000 4.50000
6.50000 7.50000 8.50000
10.5000 11.5000 12.5000
corresponding to the locations:

(.5,.5), (1.5, .5), (2.5, .5),

(.5,1.5), (1.5, 1.5), (2.5, 1.5),

(.5,2.5), (1.5, 2.5), (2.5, 2.5)

Another example computes interpolates, with GRID not set and a parameter outside the bounds of P:

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5, 3.1], [.5, 1.5, 2.5, 2])
and prints the result:

2.50000 7.50000 12.5000 11.0000
corresponding to the locations (.5,.5), (1.5, 1.5), (2.5, 2.5) and (3.1, 2.0). Note that the last location is outside the bounds of P and is set from the value of the last column. The following command uses the MISSING keyword to set such values to -1:

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5, 3.1], [.5, 1.5, 2.5, 2], $

MISSING = -1)
and gives the result:

2.50000 7.50000 12.5000 -1.00000
Syntax
Result = INTERPOLATE( P, X [, Y [, Z]] [, CUBIC=value{-1 to 0}] [, /DOUBLE] [, /GRID] [, MISSING=value] )

IDL> arr1=findgen(2,2)
IDL> print,arr1
     0.000000      1.00000
      2.00000      3.00000
IDL> print,interpolate(arr1,0.5)
      1.00000      2.00000
IDL> print,interpolate(arr1,[0,0.5,1.5])
     0.000000      1.00000
      1.00000      2.00000
      2.00000      3.00000
IDL> print,interpolate(arr1,[0,0.5,1.5],[0,0.5,1.5])
     0.000000      1.50000      3.00000
IDL> print,interpolate(arr1,[0,0.5,1.5],[0,0.5,1.5],/grid)
     0.000000     0.500000      1.00000
      1.00000      1.50000      2.00000
      2.00000      2.50000      3.00000

@3、陣列反轉–REVERSE()
The REVERSE function reverses the order of one dimension of an array.
Syntax
Result = REVERSE( Array [, Subscript_Index] [, /OVERWRITE] )
Subscript_Index
An integer specifying the dimension index (1, 2, 3, etc.) that will be reversed. This argument must be less than or equal to the number of dimensions of Array. If this argument is omitted, the first subscript is reversed.

IDL> print,arr
       0       1
       2       3
IDL> ;行反轉
IDL> print,reverse(arr,1); 1是一維,行優先
       1       0
       3       2
IDL> ;列反轉
IDL> print,reverse(arr,2)
       2       3
       0       1

@4、陣列轉置–TRANSPOSE()
The TRANSPOSE function returns the transpose of Array. If an optional permutation vector is provided, the dimensions of Array are rearranged as well.
Syntax
Result = TRANSPOSE( Array [, P] )
P
A vector specifying how the dimensions of Array will be permuted. The elements of P correspond to the dimensions of Array; the ith dimension of the output array is dimension P[i] of the input array. Each element of the vector P must be unique. Dimensions start at zero and can not be repeated.

If P is not present, the order of the dimensions of Array is reversed.

IDL> print,arr
       0       1
       2       3
IDL> print,transpose(arr,[1,0])
       0       2
       1       3

@5、陣列旋轉–ROTATE()
The ROTATE function returns a rotated and/or transposed copy of Array. ROTATE can only rotate arrays in multiples of 90 degrees. To rotate by amounts other than multiples of 90 degrees, use the ROT function. Note, however, that ROTATE is more efficient.

ROTATE can also be used to reverse the order of elements in vectors. For example, to reverse the order of elements in the vector X, use the expression ROTATE(X,2). If X = [0,1,2,3] then ROTATE(X,2)yields the resulting array, [3,2,1,0].
Syntax
Result = ROTATE(Array, Direction)
Direction
Direction specifies the operation to be performed as follows:
這裡寫圖片描述
圖11 旋轉-direction

IDL> arr1=indgen(2,3)
IDL> print,arr1
       0       1
       2       3
       4       5
IDL> print,rotate(arr1,1)
       4       2       0
       5       3       1
IDL> print,rotate(arr1,0)
       0       1
       2       3
       4       5
IDL> print,rotate(arr1,2)
       5       4
       3       2
       1       0
IDL> print,rotate(arr1,3)
       1       3       5
       0       2       4
IDL> print,rotate(arr1,4)
       0       2       4
       1       3       5
IDL> print,rotate(arr1,5)
       1       0
       3       2
       5       4
IDL> print,rotate(arr1,6)
       5       3       1
       4       2       0
IDL> print,rotate(arr1,7)
       4       5
       2       3
       0       1

Rot()函式:
The ROT function rotates an image by an arbitrary amount. At the same time, it can magnify, demagnify, and/or translate an image.
*===============================================================
DIST()函式:

The DIST function creates an array in which each array element value is proportional to its frequency. This array may be used for a variety of purposes, including frequency-domain filtering
Syntax
Result = DIST(N [, M])

N
The number of columns in the resulting array.

M
The number of rows in the resulting array. If M is omitted, the resulting array will be N by N.

IDL> TVSCL,dist(200)

這裡寫圖片描述
圖12 DIST imge
*===============================================================
Syntax
Result = ROT( A, Angle, [Mag, X0, Y0] [, /INTERP] [, CUBIC=value{-1 to 0}] [, MISSING=value] [, /PIVOT] )

ANGLE
Angle of rotation in degrees clockwise.

MAG
An optional magnification factor. A value of 1.0 results in no change. A value greater than one performs magnification. A value less than one but greater than zero performs demagnification.

X0
X subscript for the center of rotation. If omitted, X0 equals the number of columns in the image divided by 2.

Y0
Y subscript for the center of rotation. If omitted, Y0 equals the number of rows in the image divided by 2.

IDL> ; Create a byte image:
IDL> A = BYTSCL(DIST(256))
IDL> 
IDL> ; Display it:
IDL> TV, A
IDL> 
IDL> ; Rotate the image 33 degrees, magnify it 15 times, and use
IDL> ; bilinear interpolation to make the output look nice:
IDL> B = ROT(A, 33, 1.5, /INTERP)

這裡寫圖片描述
圖12 TV A
這裡寫圖片描述
圖13 TV B
@6、陣列平移–Shift()函式
The SHIFT function shifts elements of vectors or arrays along any dimension by any number of elements. Positive shifts are to the right while left shifts are expressed as a negative number. All shifts are circular.

Elements shifted off one end wrap around and are shifted onto the other end. In the case of vectors the action of SHIFT can be expressed:

Result(i + s) modulation = Arrayi for (0 ≤ 1 < n)

where s is the amount of the shift, and n is the number of elements in the array.

Syntax
Result = SHIFT(Array, S1, …, Sn)

IDL> arr=indgen(4,4)
IDL> print,arr
       0       1       2       3
       4       5       6       7
       8       9      10      11
      12      13      14      15
IDL> print,shift(arr,1)
      15       0       1       2
       3       4       5       6
       7       8       9      10
      11      12      13      14
IDL> print,shift(arr,-2)
       2       3       4       5
       6       7       8       9
      10      11      12      13
      14      15       0       1
IDL> print,shift(arr,1,1)
      15      12      13      14
       3       0       1       2
       7       4       5       6
      11       8       9      10
IDL> ;陣列X方向右移一個元素,Y方向向下移動一個元素

@7、陣列排序–Sort()函式
The SORT function returns a vector of subscripts that allow access to the elements of Array in ascending order.
Syntax
Result = SORT(Array [, /L64] )
L64
By default, the result of SORT is 32-bit integer when possible, and 64-bit integer if the number of elements being sorted requires it. Set L64 to force 64-bit integers to be returned in all cases.

Note: Only 64-bit versions of IDL are capable of creating variables requiring a 64-bit sort. Check the value of !VERSION.MEMORY_BITS to see if your IDL is 64-bit or not.

IDL> arr=[5,3,4,2,6,1,34,45]
IDL> print,sort(arr)
           5           3           1           2           0           4           6           7
IDL> print,arr(sort(arr))
       1       2       3       4       5       6      34      45

@8、求不同值–Uniq()函式
The UNIQ function returns the subscripts of the unique elements in an array. Note that repeated elements must be adjacent in order to be found. This routine is intended to be used with the SORT function: see the examples below. This function was inspired by the UNIX uniq(1) command.
返回相鄰元素不同值的索引,如果先對陣列進行排序,則可求出陣列中包含的不同值。

IDL> arr=[5,3,4,2,6,1,34,45]
IDL> print,sort(arr)
           5           3           1           2           0           4           6           7
IDL> print,arr(sort(arr))
       1       2       3       4       5       6      34      45
IDL> arr=[1,2,1,3,3]
IDL> print,arr[uniq(arr)]
       1       2       1       3
IDL> print,uniq(arr)
           0           1           2           4
IDL> arr=[1,2,1,3,3,3]
IDL> print,uniq(arr)
           0           1           2           5
IDL> print,arr(uniq(arr(sort(arr))))
       2       1       3         

@9、判斷陣列–Array_Equal()函式
The ARRAY_EQUAL function is a fast way to compare data for equality in situations where the index of the elements that differ are not of interest. This operation is much faster than using TOTAL(A NE B), because it stops the comparison as soon as the first inequality is found, an intermediate array is not created, and only one pass is made through the data. For best speed, ensure that the operands are of the same data type.

Arrays may be compared to scalars, in which case each element in the array is compared to the scalar. For two arrays to be equal, they must have the same number of elements. If the types of the operands differ, the type of the least precise is converted to that of the most precise, unless the NO_TYPECONV keyword is specified to prevent it. This function works on all numeric types, strings, pointer references, and object references. In the case of pointer and object references, ARRAY_EQUAL compares the references (which are long integers), not the heap variables to which the references point.
Syntax
Result = ARRAY_EQUAL( Op1 , Op2 [, /NO_TYPECONV ] )
NO_TYPECONV
By default, ARRAY_EQUAL converts operands of different types to a common type before performing the equality comparison. Set NO_TYPECONV to disallow this implicit type conversion. If NO_TYPECONV is specified, operands of different types are never considered to be equal, even if their numeric values are the same.

IDL> print,arr1
       1       1
IDL> print,arr2
   1   1
IDL> print,array_equal(arr1,arr2)
   1
IDL> print,array_equal(arr1,arr2,/no_typeconv)
   0
IDL> help,arr2
ARR2            BYTE      = Array[2]
IDL> help,arr1
ARR1            INT       = Array[2]

@10、求元素個數-N_Elements()函式

IDL> print,N_Elements(arr1)
           2

@11、求最大值–Max()函式

The MAX function returns the value of the largest element of Array.
Syntax
Result = MAX( Array [, Max_Subscript] [, /ABSOLUTE] [, DIMENSION=value] [, MIN=variable] [, /NAN] [, SUBSCRIPT_MIN=variable])
MIN
A named variable to receive the value of the minimum array element. If you need to find both the minimum and maximum array values, use this keyword to avoid scanning the array twice with separate calls to MAX and MIN.

IDL> print,arr
      23      34     546     567     223
IDL> print,Max(arr)
     567
IDL> print,Max(arr,Min=minval)
     567
IDL> print,Min
% PRINT: Variable is undefined: MIN.
% Execution halted at: $MAIN$          
IDL> print,minval
      23

@12、求最小值–Min()函式
同Max函式類似
@13、求和–Total()函式
The TOTAL function returns the sum of the elements of Array. The sum of the array elements over a given dimension is returned if the Dimension argument is present.
Syntax
Result = TOTAL( Array [, Dimension] [, /CUMULATIVE] [, /DOUBLE] [, /INTEGER] [, /NAN] [, /PRESERVE_TYPE] )
CUMULATIVE
If this keyword is set, the result is an array of the same size as the input, with each element, i, containing the sum of the input array elements 0 to i. This keyword also works with the Dimension parameter, in which case the sum is performed over the given dimension. Note that if the input only has a single element, then a scalar is returned.

Tip: If the input array is a temporary variable or an expression, and the result type matches the input type (for example by using the PRESERVE_TYPE keyword), then TOTAL will perform the cumulative sum in place and no additional memory will be used.

IDL> print,a
      5.00000     -1.00000      3.00000
      2.00000     0.000000      1.00000
      3.00000      2.00000      1.00000
IDL> print,total(a)
      16.0000
IDL> print,total(a,/cumulative)
      5.00000      4.00000      7.00000
      9.00000      9.00000      10.0000
      13.0000      15.0000      16.0000
IDL> print,total(a,1)
      7.00000      3.00000      6.00000
IDL> print,total(a,2)
      10.0000      1.00000      5.00000

@14、乘積計算–Product()函式
同Total類似
@15、階乘計算–Factorial()函式

IDL> print,factorial(6)
       720.00000

@16、平均值計算–Mean()函式

IDL> print,a
      5.00000     -1.00000      3.00000
      2.00000     0.000000      1.00000
      3.00000      2.00000      1.00000
IDL> print,mean(a)
      1.77778

@17、方差計算–Variance()函式
n-1作為除數

IDL> print,variance(a)
      3.19444

@18、標準差計算–Stddev()函式

IDL> print,stddev(a)
      1.78730

@19、平均值、方差、傾斜度及頻率曲線峰態計算

IDL> print,moment(a)
      1.77778      3.19444     0.177792     -1.01256

7、矩陣運算

A#B:a的列乘以B的行
A##B:a的行乘以B的列

IDL> print,b
       0       1
       2       3
       3       4
IDL> print,c
       0       1       2
       3       4       5
IDL> print,b#c