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

Home » Public Forums » archive » Re: Having trouble stopping a loop (or loop de loop de loop)
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: Having trouble stopping a loop (or loop de loop de loop) [message #62155 is a reply to message #62153] Tue, 26 August 2008 04:57 Go to previous messageGo to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Aug 26, 6:09 am, Chris <beaum...@ifa.hawaii.edu> wrote:
> this will hopefully get you started...
;;;

; Some sample data
seed = 12L
a = 0.5
u = 1e3
e_t = 1.4
file = randomu(seed, 2, 200) * 1e2

; Open the file at the start as Chris Beaumont suggested
output = 'g:\Mars_tectonics\IDL_programs\paper_m_data\alba_eflank.txt '
openw, lun, /get_lun, output

; Extract the column of data rather than lugging
; around the entire 'file' array. This also
; simplifies indexing in the program
column = file[1,*]

; Use IF rather than WHILE to prevent getting trapped
if e_t lt 2 then begin

; You can vectorise out this loop too,
; but indexing gets messy and it uses
; a LOT of memory on my machine
for n = 1, 5 do begin
x = n*4e3
v = a*x

; You only need one call to WHERE if the
; complement keywords are used
ind_small = where(column lt 2*x, count, $
complement = ind_large, ncomplement = compcount)
if count eq 0 then te_small=0 else begin
le_small = column[ind_small]
te_small = total(le_small^3)
endelse
if compcount eq 0 then te_large=0 else begin
le_large = column[ind_large]
te_large = total(le_large)
endelse

; Vectorisation of inner two FOR loops
o = rebin(50.0*!pi/180.0 + findgen(3) * (10.0*!pi/180.0), 3,2)
c = rebin(transpose([0.06, 0.1]), 3,2)

kns=(sin(o)*cos(o)/v)
knl=(c*cos(o)*x/a/sin(o))

ens= (kns*c/u)*te_small
enl= knl*te_large
; e_t is now a (3*2) array
e_t= ens+enl

; this replaces the simple 'if' statement
; in the original code
ind1 = where(e_t ge 0.45, c1)
ind2 = where(e_t le 0.9, c2)

; Any indices that fulfil our criteria?
if (c1 gt 0) && (c2 gt 0) then begin
ind3 = setintersection(ind1, ind2)
if ind3[0] ge 0 then begin

; If so, write to file
c3 = n_elements(ind3)
; There's got to be a better way of writing
; to file than looping through, but I can't
; get my head around it right now :-)
for i = 0, c3-1 do begin
j = ind3[i]
printf, lun, x, c[j], o[j], e_t[j], format='(4f9.4)'
endfor

endif
endif

endfor
endif

; close the file
free_lun, lun

;;; END

Regards,
Chris
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Matching Lats and Lons from two arrays
Next Topic: Re: heap_free fatal error

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

Current Time: Wed Oct 08 19:02:56 PDT 2025

Total time taken to generate the page: 0.00707 seconds