idl_教程(编辑修改稿)内容摘要:

tore the variables saved in the file “” you would execute the mand: IDL RESTORE, ‟‟ A save file can be used to store your data in a form that is ready to be used by IDL, transfer data across platforms in a platform independent manner, and hide the source code of userwritten routines. Working in IDL In an IDL session, data (. numbers and strings) is stored in what‟s known as variables. There are 3 basic types of IDL variables: IDL Short Course (version ) Research Systems, Inc. – A Kodak Company IDL is a registered trademark of Research Systems, Inc. Page 7 of 37  Scalar (a single value)  Array (from 1 to 8 dimensions。 a Vector is an array with only 1 dimension)  Structure (an aggregate of various data types and other variables) Any given variable in IDL also has a specific data type. There are 12 basic atomic data types (seven different types of integers, two floatingpoint types, two plex types, and a string). These data types are delineated in Figure 2. The data type assigned to a variable is determined either by the syntax used when creating the variable, or as a result of some operation that changes the type of the variable. Figure 2: IDL data types Variables do not have to be declared in IDL. The type of a variable can be determined by its usage. If a variable is set equal to the sum of two integers, the variable will end up being an integer. For example, start by declaring a scalar variable named “a” and set it equal to a 16bit signed INTEGER value of (2): IDL a = 2 Next, declare a second scalar variable called “b” and set it equal to (5): IDL b = 5 You can now perform an arithmetic operation on these two variables and store the result in a new variable called “c” without having to first declare “c”: IDL c = a + b Since both variables “a” and “b” are of type INTEGER, so is the resulting variable “c”: IDL help, a, b, c A INT = 2 B INT = 5 C INT = 7 The IDL language is dynamically typed. This means that an operation on a variable can change not only its value but also that variable39。 s data type. In general, IDL Short Course (version ) Research Systems, Inc. – A Kodak Company IDL is a registered trademark of Research Systems, Inc. Page 8 of 37 when variables of different types are bined in an expression, the result has the data type that yields the highest precision. For instance, go back and redefine the variable “b” as a 32bit FLOATINGPOINT value of (5) and perform the same arithmetic operation again: IDL b = IDL c = a + b Even though the varialbes “a” and “b” have different data types, IDL will still allow operations on these variables together in the same statement: IDL help, a, b, c A INT = 2 B FLOAT = C FLOAT = You will notice that the resulting variable “c” now takes on the data type of the highest precision for the variables that were used in the operation to create “c”, which in this case is FLOATINGPOINT (variable “b”). You can also convert the data type of variables by using any of the type conversion routines listed in Figure 2 under the “Convert To” column. For example, to convert the variable “c” back to INTEGER you would use the FIX function: IDL c = FIX (c) IDL help, c C INT = 7 However, dynamic typing can also lead to problems if you are not careful. For instance, the precision of arithmetic operations is dictated by the variable‟s data type. For example, if you define a variable “d” and set it to an INTEGER value of (5), the following division is performed with “integer precision” because both “a” and “d” are of type INTEGER: IDL d=5 IDL help, a, b, c, d A INT = 2 B FLOAT = C FLOAT = D INT = 5 IDL print, d / a 2 In order to perform floating division, at least one of the variables has to have a data type of FLOATINGPOINT: IDL print, b / a IDL is also an arrayoriented language, which means that operations occur on entire arrays at once without the need for loops. For example, declare a variable called “array” as a subscript value array of type INTEGER with 2 dimensions of size 5 columns and 5 rows: IDL array = INDGEN (5,5) IDL Short Course (version ) Research Systems, Inc. – A Kodak Company IDL is a registered trademark of Research Systems, Inc. Page 9 of 37 IDL help, array ARRAY INT = Array[5, 5] IDL print, array 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 This creates a 2dimensional array where each element is set to the value of its onedimensional subscript. IDL is a rowmajor language, which means that arrays are internally indexed in memory according to row in order of the subscript values illustrated in this array. You can also manually define arrays (and vectors) manually using the [ ] operators, which are used for array concatenation: IDL vector = [0,1,2,3,4] IDL array = [ [0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],[15,16,17,18,19], [20,21,22,23,24] ] IDL help, vector, array VECTOR INT = Array[5] ARRAY INT = Array[5, 5] In order to add the scalar value contained in the variable “d” to each element of this array, only one statement needs to be executed: IDL array = array + d IDL print, array 5 6 7 8 9 10 11 12 13 14 15。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。