On Dec 5, 9:53 pm, "skymaxw...@gmail.com" <skymaxw...@gmail.com>
wrote:
> Good day !
>
> Does IDL have some instrument like vector type in C++ ?
> I have array MxN, but it's fixed. I want insert some rows there. How ?
Not like C++, which in this case is a big advantage of IDL, as it has
much nicer semantics. I find the C++ STL too awkward for more than 1D,
which is why I tend to make my own templates to use C++ vectors in a
similar way to IDL's arrays.
Note that in IDL arrays are column-major (the fastest varying
dimension is the leftmost), the opposite of C++.
A few examples to give you just a taste of the semantics:
a=[1,2,3,4]
print,a
; 1 2 3 4
a=[a,5,6,7]
print,a
; 1 2 3 4 5 6 7
a=[a[0:3],-1,-2,a[4:6]]
print,a
; 1 2 3 4 -1 -2 5
6 7
a=bindgen(2,3)
print,a
; 0 1
; 2 3
; 4 5
a=[a,transpose([-1,-2,-3])]
print,a
; 0 1 -1
; 2 3 -2
; 4 5 -3
a=[a,[[-4,-5],[-6,-7],[-8,-9]]]
print,a
; 0 1 -1 -4 -5
; 2 3 -2 -6 -7
; 4 5 -3 -8 -9
a=bindgen(2,3)
print,a
; 0 1
; 2 3
; 4 5
a=[[a],[-1,-2]]
print,a
; 0 1
; 2 3
; 4 5
; -1 -2
a=[[a],[[-3,-4],[-5,-6]]]
print,a
; 0 1
; 2 3
; 4 5
; -1 -2
; -3 -4
; -5 -6
a=[1,2,3]
print,a
; 1 2 3
a=reform(a,1,3)
print,a
; 1
; 2
; 3
a=rebin(a,2,3)
print,a
; 1 1
; 2 2
; 3 3
Also very useful are the ability to index multidimensional arrays by
single indices, use vector indices, treat contiguous slices as if the
remaining dimensions (to the right) did not exist, routines that work
with any number of dimensions, and some very powerful functions to use
and manipulate arrays, like where, value_locate, array_indices, rebin,
reform, and histogram.
A few good references are
http://www.dfanning.com/tips/array_concatenation.html
http://www.dfanning.com/tips/rebin_magic.html
And others in David's site.
|