comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: wrong results...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: wrong results... [message #43798] Mon, 02 May 2005 14:34 Go to next message
R.G. Stockwell is currently offline  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 #43799 is a reply to message #43798] Mon, 02 May 2005 14:31 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
"elias" <elias.roussos@gmail.com> wrote in message
news:1115041740.084382.99550@f14g2000cwb.googlegroups.com...
> Hi,
>
> 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...).

> However, I am getting in the new data file created, values of longitude
> more than 600 sometimes.... I am not sure why this happens
>

Look at the lines:

if dlon lt 0 then begin
data.field3[i]=360+data.field3[i]

endif



I would guess that you mean to add 360 to dlon here, instead
of datafield3[i].

You have two lines adding 360 to data.field3, so my guess is that is
why you are seeing the ~600 values.

Cheers,
bob
Re: wrong results... [message #43806 is a reply to message #43799] Mon, 02 May 2005 08:32 Go to previous messageGo to next message
K. Bowman is currently offline  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 Go to previous messageGo to next message
elias is currently offline  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 #43808 is a reply to message #43807] Mon, 02 May 2005 07:08 Go to previous messageGo to next message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <1115041740.084382.99550@f14g2000cwb.googlegroups.com>,
"elias" <elias.roussos@gmail.com> wrote:

> 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.

Try

lon = (lon + 360.0) MOD 360.0


Ken Bowman
Re: wrong results... [message #43809 is a reply to message #43808] Mon, 02 May 2005 07:31 Go to previous messageGo to next message
yp is currently offline  yp
Messages: 42
Registered: February 2005
Member
elias wrote:
> Hi,
>
> 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


Logical error!
Just add 180. to your previous data array [-180.,180.]. i.e.
lon=lon+180.
Re: wrong results... [message #43810 is a reply to message #43808] Mon, 02 May 2005 07:29 Go to previous messageGo to next message
David Fanning is currently offline  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 Go to previous message
yp is currently offline  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 Go to previous message
David Fanning is currently offline  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/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: idlgrcontour missing contours
Next Topic: Tricky data-summing question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:34:18 PDT 2025

Total time taken to generate the page: 0.00714 seconds