Re: A strange error with WHERE [message #67474] |
Thu, 30 July 2009 21:24  |
Lindzen
Messages: 4 Registered: July 2009
|
Junior Member |
|
|
On 7月31日, 下午12时11分, David Fanning <n...@dfanning.com> wrote:
> Lindzen writes:
>> It's not that problem. Please see below:
>
>> PRINT, WHERE(lon_aoc ge 117.25)
>> 1708 1799 .....
>> PRINT, WHERE(lon_aoc ge lon_left)
>> -1
>> PRINT, lon_left
>> 117.25
>
>> Well. Maybe I need to check whether there exist strange characters in
>> the code, although it is almost impossible.
>
> OK, here is what I think is wrong, then.
> I think lon_left is not a scalar. I think
> it is a one-element array. It needs to be
> a scalar. This will probably work:
>
> PRINT, WHERE(lon_aoc ge lon_left[0])
>
> Cheers,
>
> David
>
> P.S. This is known as the Gotcha That Gets You Every Time. :-)
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Hi David,
Thank you very much. It is the problem!
Lin
|
|
|
Re: A strange error with WHERE [message #67476 is a reply to message #67474] |
Thu, 30 July 2009 21:11   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Lindzen writes:
> It's not that problem. Please see below:
>
> PRINT, WHERE(lon_aoc ge 117.25)
> 1708 1799 .....
> PRINT, WHERE(lon_aoc ge lon_left)
> -1
> PRINT, lon_left
> 117.25
>
> Well. Maybe I need to check whether there exist strange characters in
> the code, although it is almost impossible.
OK, here is what I think is wrong, then.
I think lon_left is not a scalar. I think
it is a one-element array. It needs to be
a scalar. This will probably work:
PRINT, WHERE(lon_aoc ge lon_left[0])
Cheers,
David
P.S. This is known as the Gotcha That Gets You Every Time. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: A strange error with WHERE [message #67479 is a reply to message #67476] |
Thu, 30 July 2009 20:50   |
Lindzen
Messages: 4 Registered: July 2009
|
Junior Member |
|
|
On 7月31日, 上午11时44分, David Fanning <n...@dfanning.com> wrote:
> Lindzen writes:
>> However, there is nothing wrong with the assumption. I selected one
>> case which fits the IF assumption, and checked the code line by line.
>> Even if I delete the IF line, the error still exist.
>> HELP, lon_left shows that lon_left is a flot.
>> PRINT,lon_left shows the exact value of 117.25.
>> That is why I think it is strange.
>
> Well, I think there are no values in lon_aoc
> that are greater than or equal to lon_left. Have
> you checked that? :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
It's not that problem. Please see below:
PRINT, WHERE(lon_aoc ge 117.25)
1708 1799 .....
PRINT, WHERE(lon_aoc ge lon_left)
-1
PRINT, lon_left
117.25
Well. Maybe I need to check whether there exist strange characters in
the code, although it is almost impossible.
|
|
|
Re: A strange error with WHERE [message #67481 is a reply to message #67479] |
Thu, 30 July 2009 20:44   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Lindzen writes:
> However, there is nothing wrong with the assumption. I selected one
> case which fits the IF assumption, and checked the code line by line.
> Even if I delete the IF line, the error still exist.
> HELP, lon_left shows that lon_left is a flot.
> PRINT,lon_left shows the exact value of 117.25.
> That is why I think it is strange.
Well, I think there are no values in lon_aoc
that are greater than or equal to lon_left. Have
you checked that? :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: A strange error with WHERE [message #67482 is a reply to message #67481] |
Thu, 30 July 2009 20:33   |
Lindzen
Messages: 4 Registered: July 2009
|
Junior Member |
|
|
On 7月31日, 上午11时22分, David Fanning <n...@dfanning.com> wrote:
> Lindzen writes:
>> I come across a strange error with WHERE function. Could you
>> please help me to check it?
>> Here is part of the code. I will explain below the code.
>
>> outer1_begin: id_hr = where(r03_temp ge 50)
>> n_hr = n_elements(id_hr)
>
>> if (n_elements(id_hr) gt 1) then begin
>> id_max = where(r03_temp eq max(r03_temp))
>> lonc = lon_aoc(id_max)
>> latc = lat_aoc(id_max)
>
>> ii=0
>> outer2_begin: print,ii
>> ii=ii+1
>> lon_left = lonc-ii*0.5
>> lon_right = lonc+ii*0.5
>> lat_up = latc+ii*0.5
>> lat_down = latc-ii*0.5
>> id_box = where(lon_aoc ge lon_left)
>
>> Here lon_left=117.25, is a flot number. lon_aoc is a 80*30 matrix,
>> with many values larger than 117.25.
>> If I use id=where(lon_aoc ge 117.25), id returns right results.
>> However, the above code returns -1 to id_box. It is really strange.
>> Could anyone help me? Thank you very much!
>
> There is nothing wrong with the WHERE function.
> There is (certainly) something wrong with one
> of your assumptions. You will need to discover
> which one it is. The HELP and PRINT commands are
> useful for this chore.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Thanks David.
However, there is nothing wrong with the assumption. I selected one
case which fits the IF assumption, and checked the code line by line.
Even if I delete the IF line, the error still exist.
HELP, lon_left shows that lon_left is a flot.
PRINT,lon_left shows the exact value of 117.25.
That is why I think it is strange.
Lin
|
|
|
|
Re: A strange error with WHERE [message #67553 is a reply to message #67476] |
Fri, 31 July 2009 12:46  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
David Fanning wrote:
> Lindzen writes:
>
>> It's not that problem. Please see below:
>>
>> PRINT, WHERE(lon_aoc ge 117.25)
>> 1708 1799 .....
>> PRINT, WHERE(lon_aoc ge lon_left)
>> -1
>> PRINT, lon_left
>> 117.25
>>
>> Well. Maybe I need to check whether there exist strange characters in
>> the code, although it is almost impossible.
>
> OK, here is what I think is wrong, then.
> I think lon_left is not a scalar. I think
> it is a one-element array. It needs to be
> a scalar. This will probably work:
>
> PRINT, WHERE(lon_aoc ge lon_left[0])
>
> Cheers,
>
> David
>
> P.S. This is known as the Gotcha That Gets You Every Time. :-)
I enjoy watching you grok people's problems from afar. It's quite instructive when
contemplating debugging in general.
Anyhoo....
cheers,
paulv
|
|
|