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

Home » Public Forums » archive » Looping through arrays
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
Looping through arrays [message #94122] Sat, 21 January 2017 10:05 Go to next message
Ben is currently offline  Ben
Messages: 4
Registered: February 2001
Junior Member
I work with defocused stellar images and use IDL to do the photometry. This is a great platform without which I don't think I could have done anything.

But, I am self taught and have tended to just do what works and move on. Now, going back through through my code, I want to become a better person and clean up some of the Fortran-like inclusions.

For example, over a night's observations I might have 50 sets, 5 images each of the same target and I loop through them like this:

index = 0
For m = 0, n_groups-1 do begin
For k = 0, n_imagespergroup-1 do begin
image[*,*,k] = readfits(Files(index,hdr,/silent)
index += 1
endfor ;k

;(do some stuff on this group of images}

endfor ;m (go on to the next group)

I'm wondering if there would be a more IDL-like way to accomplish the same thing. Does anyone have any ideas?
Re: Looping through arrays [message #94123 is a reply to message #94122] Sat, 21 January 2017 10:46 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
The main change I would suggest is to replace

image[*,*,k] = readfits(Files[index],hdr,/silent)

with

image[0,0,k] = readfits(Files[index],/silent)

http://www.idlcoyote.com/code_tips/asterisk.html

(I also omit the 'hdr' output parameter. You never use it so no need to create it.)

Loops in IDL are OK so long as you get a lot of work done on each iteration, which your program already does. --Wayne


On Saturday, January 21, 2017 at 1:05:24 PM UTC-5, Ben wrote:
> I work with defocused stellar images and use IDL to do the photometry. This is a great platform without which I don't think I could have done anything.
>
> But, I am self taught and have tended to just do what works and move on. Now, going back through through my code, I want to become a better person and clean up some of the Fortran-like inclusions.
>
> For example, over a night's observations I might have 50 sets, 5 images each of the same target and I loop through them like this:
>
> index = 0
> For m = 0, n_groups-1 do begin
> For k = 0, n_imagespergroup-1 do begin
> image[*,*,k] = readfits(Files(index,hdr,/silent)
> index += 1
> endfor ;k
>
> ;(do some stuff on this group of images}
>
> endfor ;m (go on to the next group)
>
> I'm wondering if there would be a more IDL-like way to accomplish the same thing. Does anyone have any ideas?
Re: Looping through arrays [message #94124 is a reply to message #94123] Sat, 21 January 2017 12:20 Go to previous message
Ben is currently offline  Ben
Messages: 4
Registered: February 2001
Junior Member
Good to know about the asterisks. I have used them extensively and will fix that.

I actually do use the header to read in things like:
obsdate = sxpar(hdr,'date-obs')
ra = sxpar(hdr,'objctra')
dec = sxpar(hdr,'objctdec')
hour = double(strmid(obsdate,12,2))
minute = double(strmid(obsdate,14,2))
second = double(strmid(obsdate,17,2))
deg = double(strmid(dec,1,2))
amin = double(strmid(dec,4,2))
asec = double(strmid(dec,7,4))
I left a great deal of stuff out that I thought would just clutter things up.

Thanks for the feedback.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: some users will be harmed by the new licensing policy in IDL 8.6
Next Topic: Orientation of 2-d plot

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

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

Total time taken to generate the page: 0.00353 seconds