ij2index.pro
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
FUNCTION ij2index,ij,sizes
;+
; NAME:
; ij2index
; CALLING SEQUENCE:
; index=ij2index(ij,sizes)
; PURPOSE:
; returns the index in a 2D or 3D array of coo
; INPUTS:
; ij = pixel values for which the index is needed
; sizes = array dimensions
; OPTIONAL INPUT:
; None
; OUTPUTS:
; index
; PROCEDURE AND SUBROUTINE USED
; SIDE EFFECTS:
; MODIFICATION HISTORY:
; written by Jean-Philippe Bernard 09-92
; EXAMPLE:
; a=fltarr(12,15,17)
; a(10,10,5)=1 & a(11,5,16)=1
; ind=where(a NE 0,count)
; ij=index2ij(ind,[12,15,17])
; help,ij
; print,ij
; ind2=ij2index(ij,[12,15,17])
; print,ind,ind2
;-
;on_error,2
IF n_params(0) NE 2 THEN BEGIN
print,'Calling sequence: index=ij2index(coo,sizes)'
goto,sortie
ENDIF
taille = n_elements(sizes)
index = round(ij(*,0))
prod = 1l
FOR i=0l,taille-2 DO BEGIN
prod = prod*sizes(i)
index = index + prod*round(ij(*,i+1))
ENDFOR
;IF n_params(0) EQ 3 THEN BEGIN
; index=1l*(coo(*,2)*sx*sy+coo(*,1)*sx+coo(*,0))
;ENDIF ELSE BEGIN
; index=1l*(coo(*,1)*sx+coo(*,0))
;ENDELSE
RETURN,index
sortie:
end