Looping through arrays [message #94122] |
Sat, 21 January 2017 10:05  |
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   |
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  |
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.
|
|
|