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 
Return to the default flat view Create a new topic Submit Reply
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 previous 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)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
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 11:41:35 PDT 2025

Total time taken to generate the page: 0.00441 seconds