0

unfortunately I couldn't find an answer to this issue, and have had to result to asking a question. If there is an answer elsewhere, I apologise, I am new to IDL, and didn't know how to phrase this perfectly.

My code is below:

for i=0,delta-1 do begin
    print, flrarray[i]
    numbr_for_arr=where(del gt ((flrarray[i])-0.000001) and del lt ((flrarray[i])+0.000001))
    print,numbr_for_arr
    postnflrarray[i]=numbr_for_arr
endfor

delta is just a number. finalflrarray is just an array that has specific points that I need from del (a huge array)

my output is below:

   ...
   24.000231 ; flrarray
   23392 ; numbr_for_arr
   24.748374
   26612
   24.213783
   27473
   24.368324
   30637
   24.711283
   32432
   24.426823
   37675
   24.039426
   40733

Printing the flrarray, and postnflrarray

   ...       24.000231       24.748374       24.213783       24.368324       24.711283       24.426823       24.039426
   ...       23392           26612           27473           30637           32432           -27861          -24803

As you can see, somehow between printing numbr_for_array, and appending it

37675 -> -27861 and 40733 -> -24803

Any insight into why this is happening would be greatly appreciated.

I must emphasize that the flrarray array/vector is coming from an external source, so I am using this method to find where it is in my 'del' array.

Thank you for your help

Eric Brown
  • 13,774
  • 7
  • 30
  • 71

3 Answers3

1

postnflrarray needs to be a 'lonarr'

ie postnflrarray=lonarr(N) Where N is a length of the array. This comes down to the values in the array being 16-bit signed integers (max size around 32767). When you append a value larger than it, it overflows becoming negative.

0

From what you have given, it looks like you are using WHERE on a scalar. You want to use WHERE with an array argument. The result will then give the indices which match the given condition. For example, to find the elements of a sine curve greater than 0.99, do:

IDL> x = findgen(360) * !dtor
IDL> y = sin(x)
IDL> ind = where(y gt 0.99, count)
IDL> print, count
          17
IDL> print, ind
          82          83          84          85          86          87          88          89
          90          91          92          93          94          95          96          97
          98
IDL> print, y[ind]
     0.990268     0.992546     0.994522     0.996195     0.997564     0.998630     0.999391
     0.999848      1.00000     0.999848     0.999391     0.998630     0.997564     0.996195
     0.994522     0.992546     0.990268
mgalloy
  • 2,356
  • 1
  • 12
  • 10
0

I have made a slightly altered version of your code with comments:

;;  If FLRARRAY is a one-dimensional array, then you could define the
;;    following outside of the for loop
;;  updn = [[flrarray - 1e-6],[flrarray + 1e-6]]
;for i=0,delta-1 do begin
for i=0L,delta-1L do begin
  print, flrarray[i]
;  numbr_for_arr=where(del gt ((flrarray[i])-0.000001) and del lt ((flrarray[i])+0.000001))
  ;;  Note:  WHERE.PRO should be returning long integers, not integers.  However, your
  ;;         output seems to suggest otherwise which is odd.
  numbr_for_arr = where(del gt (flrarray[i] - 0.000001) and del lt (flrarray[i] + 0.000001),nmb)*1L
;;  numbr_for_arr = where(del gt updn[i,0] and del lt updn[i,1],nmb)
  print,numbr_for_arr
;  postnflrarray[i]=numbr_for_arr  ;;  what if there is more than one element?
  if (nmb GT 0) then postnflrarray[i] = numbr_for_arr[0]
endfor
honeste_vivere
  • 308
  • 5
  • 11