Re: Print format question for the Experts [message #25980] |
Thu, 02 August 2001 15:51  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
David Fanning wrote:
>
> To only print certain lines, you can do...
>
> PRO Example, K
; n*K-th lines only will be printed
> max_rec=20
> base = Widget_Base()
> text = Widget_Text(base, Value="", Scr_XSize=200, YSize=1)
> screenSize = Get_Screen_Size()
> xCenter = screenSize(0) / 2
> yCenter = screenSize(1) / 2
> geom = Widget_Info(base, /Geometry)
> xHalfSize = geom.Scr_XSize / 2
> yHalfSize = geom.Scr_YSize / 2
> Widget_Control, base, XOffset = xCenter-xHalfSize, $
> YOffset = yCenter-yHalfSize
> Widget_Control, base, /Realize
> maxnumber = StrTrim(max_rec, 2)
if n_elements(k) eq 0 then k=1
> for i=0,max_rec-1 do begin
> wait, 0.5 ; Or read a record or whatever.
if i mod k eq 0 then number = StrTrim(i, 2)
> Widget_Control, text, Set_Value='Record number ' + number + $
> ' out of ' + maxnumber + '.'
> endfor
> Widget_Control, base, /Destroy
> END
Cheers,
Pavel
|
|
|
|
|
Re: Print format question for the Experts [message #25986 is a reply to message #25984] |
Thu, 02 August 2001 12:41   |
david[2]
Messages: 100 Registered: June 2001
|
Senior Member |
|
|
John McFee writes:
> I have a question which I think should have a simple answer. Being a master of
> kludging code for physics problems, it's not surprising that I haven't been able
> to figure it out. I'm hoping the experts in this group can.
>
> I am using IDL to read records one at a time from a file and I want to print out
> a message that each record was successfully read, i.e., I would print something
> like the following for record 5:
>
> Record number 5 out of 1500
>
> Because I can have several thousand records in a run, I do not want to have a
> flowing list like:
>
> ...
> Record number 1034 out of 1500
> Record number 1035 out of 1500
> Record number 1036 out of 1500
> ...etc.
>
> but instead just want one line where the record number increments, i.e.,
>
> Record number n out of 1500 [where n changes at the same spot]
>
>
> To do that I tried the following code:
>
> i=0
> print, format='($,"Record number ",t19,i6,t27,"out of " , t28,i6)',i+1,max_rec
> for i=0,max_rec-1 do begin
> read_a_record_function
> print, format='($,tl42,i6)', i+1
> endfor
>
> What I get is something like:
>
> Record number 1 out of 1500 2 3 4 5 6 7 8 9 10 11 13 14
> 15....etc.
>
> In other words, the $ format character supresses the new line, but each new
> print sets the next line's "left-right" pointer at the right edge of the
> previous printed line.
>
> I've tried the t format char as well as the tl character with no more luck.
>
> Does anybody know how to do this?
How about this:
PRO Example
max_rec=20
base = Widget_Base()
text = Widget_Text(base, Value="", Scr_XSize=200, YSize=1)
screenSize = Get_Screen_Size()
xCenter = screenSize(0) / 2
yCenter = screenSize(1) / 2
geom = Widget_Info(base, /Geometry)
xHalfSize = geom.Scr_XSize / 2
yHalfSize = geom.Scr_YSize / 2
Widget_Control, base, XOffset = xCenter-xHalfSize, $
YOffset = yCenter-yHalfSize
Widget_Control, base, /Realize
maxnumber = StrTrim(max_rec, 2)
for I=0,max_rec-1 do begin
wait, 0.5 ; Or read a record or whatever.
number = StrTrim(I+1, 2)
Widget_Control, text, Set_Value='Record number ' + number + $
' out of ' + maxnumber + '.'
endfor
Widget_Control, base, /Destroy
END
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Print format question for the Experts [message #25987 is a reply to message #25986] |
Thu, 02 August 2001 12:24   |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
John McFee wrote:
>
> I have a question which I think should have a simple answer. Being a master of
> kludging code for physics problems, it's not surprising that I haven't been able
> to figure it out. I'm hoping the experts in this group can.
>
> I am using IDL to read records one at a time from a file and I want to print out
> a message that each record was successfully read, i.e., I would print something
> like the following for record 5:
>
> Record number 5 out of 1500
>
> Because I can have several thousand records in a run, I do not want to have a
> flowing list like:
>
> ...
> Record number 1034 out of 1500
> Record number 1035 out of 1500
> Record number 1036 out of 1500
> ...etc.
>
> but instead just want one line where the record number increments, i.e.,
>
> Record number n out of 1500 [where n changes at the same spot]
>
> To do that I tried the following code:
>
> i=0
> print, format='($,"Record number ",t19,i6,t27,"out of " , t28,i6)',i+1,max_rec
> for i=0,max_rec-1 do begin
> read_a_record_function
> print, format='($,tl42,i6)', i+1
> endfor
>
> What I get is something like:
>
> Record number 1 out of 1500 2 3 4 5 6 7 8 9 10 11 13 14
> 15....etc.
>
> In other words, the $ format character supresses the new line, but each new
> print sets the next line's "left-right" pointer at the right edge of the
> previous printed line.
>
> I've tried the t format char as well as the tl character with no more luck.
>
> Does anybody know how to do this?
Let's see, I'm no expert, but your output string has:
1 2 3
123456789012345678901234567890
Record number 1034 out of 1500
30 characters and you want the repeat to start at character #15 - so that's 16 backspaces
from the end of the string. You can try:
; Create backspace array of required length
bksp = MAKE_ARRAY( 16, VALUE = 8B )
; Output "base" string of the correct length
; Record number XXXX out of XXXX
PRINT, FORMAT = '( 2x, "Record number ", $ )'
FOR i = 1, number_of_records_to_read DO BEGIN
PRINT, FORMAT = '( a, i4, " out of ", i4, $ )', $
STRING( bksp ), i, number_of_records_to_read
......etc etc.....
ENDFOR
This is a supa kludge. You gotta make sure that the length of the format strings are all
consistent, as well as how many backspaces etc. But it seems to work just fine for me. Of
course, any other output (e.g. from message or other print statements) will screw up the
output.
paulv
p.s. STRING(8B) == ASCII character set backspace character. So, if you're using IDL on a
machine that uses EBCDIC (if they still exist?), I have no ideer.
--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
Alexander Pope.
|
|
|
sec : U Re: Print format question for the Experts [message #26122 is a reply to message #25983] |
Thu, 02 August 2001 20:22  |
Andrew Cool
Messages: 219 Registered: January 1996
|
Senior Member |
|
|
John McFee wrote:
>
> Many thanks to Paul van Delst and David Fanning. Two different but cool
> solutions. It would have taken me lots of time to figure out either on my own.
>
John,
Another "cool" answer, so to speak...
This bit of code works fine from the old TTY command line
environment as found on VMS and Unix boxes.
Doesn't work under IDLDE in the Output log window however,
in which case you need a van Delst or "von" Fanning solution.
HTH,
Andrew
pro trace_loop_test
for i = 0,100 do begin
trace_loop,i
end
end
pro trace_loop,i
cr = STRING(13B) ; ASCII Carriage-return Control Code
print,format='("Processing index Number ",i4,a,$)',i,cr
end
------------------------------------------------------------ ---------
Andrew D. Cool .->-.
Electromagnetics & Propagation Group `-<-'
Surveillance Systems Division Transmitted on
Defence Science & Technology Organisation 100% recycled
PO Box 1500, Salisbury electrons
South Australia 5108
Phone : 061 8 8259 5740 Fax : 061 8 8259 6673
Email : andrew.cool@dsto.defence.gov.au
------------------------------------------------------------ ---------
|
|
|