IDL structures array

Creating an Array of Structures


The easiest way to create an array of structures is to use the REPLICATE function. The first parameter to REPLICATE is a reference to the structure of each element. Using the example in Examples of Structure References and assuming the STAR structure has been defined, an array containing 100 elements of the structure is created with the following statement:

cat = REPLICATE({star}, 100)

Alternatively, since the variable A contains an instance of the structure STAR, then

cat = REPLICATE(A, 100)

Or, to define the structure and an array of the structure in one step, use the following statement:

cat = REPLICATE({star, name:'', ra:0.0, dec:0.0, $
    inten:FLTARR(12)}, 100)

The concepts and combinations of subscripts, subscript arrays, subscript ranges, fields, nested structures, etc., are quite general and lead to many possibilities, only a small number of which can be explained here. In general, any structures that are similar to the examples above are allowed.


It is now possible to concatenate anonymous structures as long as they have the same field sizes and types. That is to say, they do not even have to have the same field names. For example, consider this code, written in IDL 6.2.

   IDL> a = {Name: 'Larry', Age: 46}
   IDL> b = {LastName: 'Henderson', No_of_Dogs: 4}
   IDL> c = [ a, b]
   IDL> Help, c
   C               STRUCT    = ->  Array[2]
   IDL> a = b
   IDL> Help, a, /str
a = {LastName: 'Henderson', No_of_Dogs: 4}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值