Re: wrong results... [message #43798] |
Mon, 02 May 2005 14:34  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"David Fanning" <davidf@dfanning.com> wrote in message
news:MPG.1cdfe74036bd65989899e4@news.frii.com...
> elias writes:
..
> but if your data goes from -180 to 180,
> and you want it to go from 0 to 360, you will add 180 to each
> value, not 360. :-)
While that does indeed work, I'd guess the OP was not clear
in their intentions. For longitude, you would want to leave the
0 to 180 range as is, and change the -180 to 0 data to fall in the
range 180 to 360 by adding 360 to it.
i.e. -1 should become 359.
One can add 360 to longitude and "not change anything " since
they are degrees.
Cheers,
bob
|
|
|
|
Re: wrong results... [message #43806 is a reply to message #43799] |
Mon, 02 May 2005 08:32   |
K. Bowman
Messages: 330 Registered: May 2000
|
Senior Member |
|
|
In article <MPG.1cdfe74036bd65989899e4@news.frii.com>,
David Fanning <davidf@dfanning.com> wrote:
> This probably occurred to you a fraction of a second after
> you hit the SEND button, but if your data goes from -180 to 180,
> and you want it to go from 0 to 360, you will add 180 to each
> value, not 360. :-)
That would rotate the coordinate system by 180 degress, putting the dateline at
the Greenwich meridian, and vice versa. To keep 0 degrees at Greenwich, but
measure longitude from 0 to 360, rather than -180 to 180, I think he really
wants to do what was in my other post:
lon = (lon + 360.0) MOD 360.0
By the way, the reverse transformation is
lon = lon - (LONG(lon)/180)*360.0
Ken Bowman
|
|
|
Re: wrong results... [message #43807 is a reply to message #43806] |
Mon, 02 May 2005 07:54   |
elias
Messages: 13 Registered: April 2005
|
Junior Member |
|
|
David Fanning wrote:
>
> This probably occurred to you a fraction of a second after
> you hit the SEND button, but if your data goes from -180 to 180,
> and you want it to go from 0 to 360, you will add 180 to each
> value, not 360. :-)
Well, I didn't exactly notice it after I pressed the SEND button, but
just after I got my first really unreasonable results... :-)
The 360 was supposed only in the case I was calculating angular
separation between spacecraft + moon...
As for this IDL problem, maybe I don't need to fight with it anymore,
but in any case, it seems that when it changes the value from negative
to positive (by adding the 360), it somehow adds 360 for a second time
(although the if statement is not satisfied), and therefore I get these
strange values...
|
|
|
|
|
Re: wrong results... [message #43810 is a reply to message #43808] |
Mon, 02 May 2005 07:29   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
elias writes:
> The following problem probably has something to do with definitions of
> floating, integer etc, but I don't really know to solve it (although i
> am sure the solution will be simple in the end...).
>
> I have a data file that, amongst others, contains some longitude
> columns. The longitude data is defined from -180 to 180 deg in this
> data file. For some consistency with some other analysis I did before,
> I want to convert it to 0-->360 deg.
>
> So simply, I ask when it reads a longitude <0 to do: lon=360+lon
>
> However, I am getting in the new data file created, values of longitude
> more than 600 sometimes.... I am not sure why this happens
This probably occurred to you a fraction of a second after
you hit the SEND button, but if your data goes from -180 to 180,
and you want it to go from 0 to 360, you will add 180 to each
value, not 360. :-)
I don't know where 600 comes from, I would expect a maximum
value of 180 + 360 = 540. Something else must be wrong.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: wrong results... [message #43938 is a reply to message #43806] |
Tue, 03 May 2005 10:40  |
yp
Messages: 42 Registered: February 2005
|
Member |
|
|
Kenneth Bowman wrote:
>
> lon = (lon + 360.0) MOD 360.0
>
Thats brilliant!
> By the way, the reverse transformation is
>
> lon = lon - (LONG(lon)/180)*360.0
>
This is great too; but how to parse the last element? Using the above
transformation, 180.0 becomes -180.0 at both ends. This does transform
the coordinate exactlty for all elements except +180.0. Of course,
zonally 180 = -180 from a geographic perspective.
|
|
|
Re: wrong results... [message #43947 is a reply to message #43798] |
Mon, 02 May 2005 14:43  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
R.G. Stockwell writes:
> While that does indeed work, I'd guess the OP was not clear
> in their intentions. For longitude, you would want to leave the
> 0 to 180 range as is, and change the -180 to 0 data to fall in the
> range 180 to 360 by adding 360 to it.
>
> i.e. -1 should become 359.
>
> One can add 360 to longitude and "not change anything " since
> they are degrees.
After getting out a map and puzzling over this for
several minutes, I convinced myself of the truth of
Ken's algorithms. While this may be second nature to
people working with maps every day, it does take a
minute or two for the brain to get in gear for those
of us working with maps only infrequently. Since I have
a feeling this is one of those things I could embarrass
myself with again, I've decided to write it down and
make it available to everyone. Now, if I can just remember
I put it on my web page... :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|