IDL common block

来源:互联网 发布:如何禁止系统安装软件 编辑:程序博客网 时间:2024/04/27 09:24

Note on Common Block Variable Names

Variables in IDL COMMON blocks do not actually have names. Rather, IDL represents COMMON blocks internally as an array of variables, and these variables are referenced by their positional index. Hence, the first variable is at position 0, the second at position 1, and so forth. When you specify a COMMON block declaration in an IDL routine, you specify names to be used for these variables within the scope of that routine.


Common Block Definition Statements

The common block definition statement creates a common block with the designated name and places the variables whose names follow into that block. Variables defined in a common block can be referenced by any program unit that declares that common block. The general form of the COMMON block definition statement is as follows:

COMMON Block_Name, Variable1, Variable2, ..., Variablen

The number of variables appearing in the common block cannot change after the common block has been defined. The first program unit (main program, function, or procedure) to define the common block sets the number of included variables; other program units can reference the common block with any number of variables up to the number originally specified. Different program units can give the variables different names, as shown in the example below.



Example

The two procedures in the following example show how variables defined in common blocks are shared.

PRO ADD, A
   COMMON SHARE1, X, Y, Z, Q, R
   A = X + Y + Z + Q + R
   PRINT, X, Y, Z, Q, R, A 
   RETURN 
END
 
PRO SUB, T
   COMMON SHARE1, A, B, C, D
   T = A - B - C - D
   PRINT, A, B, C, D, T
   RETURN
END 

The variables X, Y, Z, and Q in the procedure ADD are the same as the variables A, B, C, and D, respectively, in procedure SUB. The variable R in ADD is not used in SUB. If the procedure SUB were to be compiled before the procedure ADD, an error would occur when the COMMON definition in ADD was compiled. This is because SUB has already declared the size of the COMMON block, SHARE1, which cannot be extended.


0 0