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

Home » Public Forums » archive » Easy question on for loops and if statements
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
Easy question on for loops and if statements [message #91451] Thu, 16 July 2015 10:15 Go to next message
larosaant94 is currently offline  larosaant94
Messages: 3
Registered: July 2015
Junior Member
I am plotting the magnetic field longitude and using the ATAN function to do so. Though the ATAN function gives a result between the range of -180 to +180. I wish to use a range of
0 to 360.

A look at the code:

Bx = data(10,*)
By = data(11,*)

longitude = 180/!Pi* atan(By, Bx)

FOR j=0,N_Elements(longitude)-1 DO BEGIN
IF longitude[j] lt 0 THEN BEGIN
longitude = 360 + longitude
ELSE
longitude = longitude
ENDFOR

;Does the actual plotting-----------

plot, time, longitude, yrange=[0, 360], yticks=4, yminor=6, $
ytitle='Lambda', position=[0.1, 0.24, 0.95, 0.31], xtickname=blnklb
plots, [min(time), max(time)], 180.0*[1,1], linestyle=2



I want any number less than 0 to get 360 added to it and then once this is completed plot all the data points including the ones above 0!

Thanks!
Re: Easy question on for loops and if statements [message #91453 is a reply to message #91451] Thu, 16 July 2015 11:24 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 7/16/15 11:15 AM, larosaant94@gmail.com wrote:
> I am plotting the magnetic field longitude and using the ATAN
> function to do so. Though the ATAN function gives a result
> between the range of -180 to +180. I wish to use a range of
> 0 to 360.
>
> A look at the code:
>
> Bx = data(10,*)
> By = data(11,*)
>
> longitude = 180/!Pi* atan(By, Bx)
>
> FOR j=0,N_Elements(longitude)-1 DO BEGIN
> IF longitude[j] lt 0 THEN BEGIN
> longitude = 360 + longitude
> ELSE
> longitude = longitude
> ENDFOR
>
> ;Does the actual plotting-----------
>
> plot, time, longitude, yrange=[0, 360], yticks=4, yminor=6, $
> ytitle='Lambda', position=[0.1, 0.24, 0.95, 0.31], xtickname=blnklb
> plots, [min(time), max(time)], 180.0*[1,1], linestyle=2
>
>
>
> I want any number less than 0 to get 360 added to it and then once
> this is completed plot all the data points including the ones above 0!

I don't see a specific question here. I do notice you had some oddities
in your FOR loop, so I corrected:

for j = 0L, n_elements(longitude) - 1L do begin
if (longitude[j] lt 0) then begin
longitude[j] = 360 + longitude[j]
endif
endfor

But really, I would just do the following:

longitude += (longitude lt 0) * 360

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Re: Easy question on for loops and if statements [message #91455 is a reply to message #91453] Thu, 16 July 2015 11:30 Go to previous messageGo to next message
larosaant94 is currently offline  larosaant94
Messages: 3
Registered: July 2015
Junior Member
Sorry about that...

I want to plot 0 to 360 on the y axis, but the calculation only computes -180 to 180. I need to add 360 to all values less than 0 and keep the ones 0 - 180 the same with no addition!
Re: Easy question on for loops and if statements [message #91457 is a reply to message #91455] Thu, 16 July 2015 11:51 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Thursday, July 16, 2015 at 1:30:22 PM UTC-5, laros...@gmail.com wrote:
> Sorry about that...
>
> I want to plot 0 to 360 on the y axis, but the calculation only computes -180 to 180. I need to add 360 to all values less than 0 and keep the ones 0 - 180 the same with no addition!

Did you try searching for an answer?

I found this pretty quickly....

http://www.idlcoyote.com/map_tips/lonconvert.html
Re: Easy question on for loops and if statements [message #91459 is a reply to message #91457] Thu, 16 July 2015 13:37 Go to previous message
larosaant94 is currently offline  larosaant94
Messages: 3
Registered: July 2015
Junior Member
Apparently not hard enough -- thank you.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Distance calculation for lots of stars
Next Topic: Separating land and ocean data in IDL

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

Current Time: Wed Oct 08 07:14:42 PDT 2025

Total time taken to generate the page: 0.00445 seconds