Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
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/
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.
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...
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
"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
"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
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/
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.