-1

I am an R and IDL beginner. Im trying to convert an R script to IDL.

R can do array manipulation with t1 (array[100000]) but IDL cannot.

ERROR: Array subscript for CZ must have same size as source expression

s1= 100000.

c1 = array[200000]

n1 = s1*2+2

t1 = array[100000]

————————————————————————————————

(function)

f03, c1, s1, n1



cz = fltarr(n1,3)       

cz[0:((2*s1)-1),0] = c1

cz[1:(2*s1),1] = c1

cz[2:((2*1)+1),2] = c1

cr = cz[0:(n1-1),1] - cz[0:(n1-1),2]

cl = cz[0:(n1-1),1] - cz[0:(n1-1),0]

p1 = where(cr GE 0.0 AND cl GE 0.0 AND (cz[0:(n1-1),1]) GE 1.4)



n2 = n_elements(p1)

ct = fltarr(n2+1,2)

ct[0:n2-1,0] = p1 

ct[1:n2,1] = p1

c2 = ct[*,0] - ct[*,1]

ip = where(c2 GT 2.) 

ch = p1[ip]



return, ch

————————————————————————————————

p1 = f03(c1,s1,n1) ;;;;; function works here

f1 = f03(t1,s1,n1)  ;;;;; error on array size

I used MATRIX and AS.MATRIX in R (for f03). Does FLTARR cause this error?

gerrit
  • 24,025
  • 17
  • 97
  • 170

1 Answers1

0

Your lines:

cz = fltarr(n1, 3)
cz[0:((2 * s1) - 1), 0] = c1

make sense when cz has a first dimension of size 2000002 and c1 is 200000 elements — the sizes on the left and right of the = sign match, i.e., 0:199999 is 2000000 elements just like the size of c1.

But in the second call, c1 only has 100000 elements, but the left side is still asking for 2000000 elements.

Also, define a function like:

function f03, c1, s1, n1
  ; a bunch of code goes here
  return, ch
end
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • Thank you so much mgalloy. yes, that is the problem. but i do not know how to solve it. Anyway, thank you so much. – john23wenx Jun 21 '18 at 08:15