IDL common block

本文介绍了IDL语言中COMMON块的概念及使用方法。详细解释了如何定义和引用COMMON块内的变量,并通过示例展示了不同程序单元间如何共享这些变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值