Displaying loop-index (was: Re [Q] illegal character ?) [message #2608] |
Fri, 12 August 1994 05:01 |
knipp
Messages: 68 Registered: January 1993
|
Member |
|
|
IDL. Version 3.1.1 (sunos sparc)
Hi
Two or three years ago I wanted to keep track of the index
in a loop, i.e. displaying tha actual index in the loop.
Naturally I wanted just one line as output overwrinting that
line again and again.
I came up with a solution using "\x08" which I had to change
to string(8b) about a year ago.
The discussion in this group about " [Q] illegal character " gave
me -finally :-) - the idea to use string(13b) instead of
string(8b).
So now I have two routines for the same task (I'll append them
at the end - they're just a couple of lines long). I timed them
against each other:
n_lines n'th line TIME 8b TIME 13b ratio
100 1 0.96499991 0.59800005 1.6137121
1000 1 9.7730000 5.4520000 1.7925532
10000 1 97.016000 55.228000 1.7566452
100 50 0.038999915 0.021000028 1.8571364
1000 50 0.22299993 0.21700001 1.0276494
10000 50 2.3700000 2.1220001 1.1168708
with n_lines: number of loops
n'the line: display every n'th loop-index
TIME: in seconds
ratio: (TIME 8b) / (TIME 13b)
As you can see using string(13b) seems to be faster.
If anyone of you has ideas to speed them up please inform me.
Karlheinz Knipp
____________________________________________________________ __________________
__ ____ __
/ // _ \ / / Karlheinz Knipp phone: +49 511 - 762 4922
/ // /_/ // / University of Hannover fax: +49 511 - 762 2483
/ // ____// / Institute for Photogrammetry
/ // / / / Nienburger Str.1
/_//_/ /_/ FRG 30167 Hannover e-mail: knipp@ipi.uni-hannover.de
vvvvvvvvvvvvvvvvvvvvvvvvv SNIP vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;+
pro show_line, l, nl, maxl = maxl
; shows line in loop
; ------------------------------------------------------------ ------------------
; START OF DESCRIPTION
;
; subroutine IPI, U Hannover 08'91, modified 12'91
; 04'93: changed x08 > string(8b)
; 08'94: modified for less if's
;
; METHOD: print (with reset) line # (or line# - line# mod nl)
; formats : $ NO carr.return
; "\x08" one backspace OLD
; string(8b) NOW
;
; INPUT PARAMETER: l current line number
; nl every n'th line to be printed
;
; OUTPUT PARAMETER: none
;
; KEYWORDS : maxl if set, maximal line in loop (wiil be displayed)
;
; EXAMPLE:
;
; print,format='($,"# :")' & for l=0,2500 do show_line,l,100,maxl=2500 & print
;
; END OF DESCRIPTION
; ------------------------------------------------------------ ------------------
;-
; ------------------------------------------------------------ ------------------
; test input - no test for faster processing
; ------------------------------------------------------------ ------------------
; make it
ll = l+1
if (ll mod nl) eq 0 then begin
bspc = string(8b) + string(8b) + string(8b) + string(8b) + string(8b) + $
string(8b) + string(8b) + string(8b) + string(8b) + string(8b) + $
string(8b) + string(8b) + string(8b) + string(8b) + string(8b) + $
string(8b) + string(8b) + string(8b) + string(8b) + string(8b) + $
string(8b) ; + string(8b) + string(8b) + string(8b) + string(8b)
if n_elements(maxl) eq 0 $
then smax = ' ' $
else smax = ' / ' + string(format='(i8)',maxl+1l)
print, format='($, i10, a, a)', ll, smax, bspc
endif
; ------------------------------------------------------------ ------------------
; return & end
return
end
;+
pro s_line, line, dummy, eline=eline, maxl=maxl, text=text
; shows actual line in loop
; ------------------------------------------------------------ --------------
; START OF DESCRIPTION
;
; subroutine IPI, U Hannover 08'94
; 08'94:
;
; METHOD: shows actual line in loop
; usinf <cr> = string(13b)
;
; INPUT PARAMETER: line actual line
; dummy dummy input for comp. with SHOW_LINE
;
; OUTPUT PARAMETER: none
;
; INPUT KEYWORDS : eline every nth line to display info [1]
; maxl last line !! STRING !! ['']
; text text to display [' actual ... ']
;
; OUTPUT KEYWORDS : none
;
; EXAMPLE:
;
; for i=0,99 do s_line, i, eline=1, maxl='99', text = 'DEMO ...' & print
;
; END OF DESCRIPTION
; ------------------------------------------------------------ --------------
;-
; ------------------------------------------------------------ --------------
; test input / no test for faster proc
; ------------------------------------------------------------ --------------
; test keywords
if n_elements(eline) ne 1 then eline = 1l
eline = 1 > eline
; ------------------------------------------------------------ --------------
; do it
if (line mod eline) eq 0 then begin
CR = string(13b)
smax = ''
if n_elements(maxl) eq 1 then $
if strtrim(maxl,2) ne '' then $
smax = ' / ' + strtrim(string(maxl),2)
if n_elements(text) ne 1 then text = ' actual ... '
text = string(text)
print, format='(a,a,i,a,$)', CR, text, line, smax
endif
; ------------------------------------------------------------ --------------
; return & end
rtcode = 0
return
end
^^^^^^^^^^^^^^^^^^^^^^^^^ SNAP ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|