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

Home » Public Forums » archive » Re: Q: Use of variables with FORMAT
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: Q: Use of variables with FORMAT [message #7832] Thu, 09 January 1997 00:00
gunter is currently offline  gunter
Messages: 13
Registered: October 1996
Junior Member
I (gunter@alpha1.csd.uwm.edu) wrote the following clueless post:

: Suppose I need to print a line of 100 3-digit integers including a single
: space in between each one. Then I would use the following:
:
: printf, unit, data_array, format='(100I4)'
:
: where the data_array contains 100 elements in this case. However, this line
: appears inside of a routine to wich data_array is passed and data_array does
: not always contain 100 elements. Is there some way of replacing the '100'
: in the above line with a variable? I've tried the obvious ways I could
: think of, to no avail.

Of course I didn't think of the MOST obvious solution, as pointed out to me by
a few people. Since the FORMAT keyword wants a string, just assemble it based
on the number of elements in the data_array. This works:

form_string = "'(" + strtrim(string(n_elements(data_array)),2) + "I4)'"
printf, unit, data_array, format=form_string

Note the use of the double quotes so that the single quote can be included.

-david
[Message index]
 
Read Message
Previous Topic: Starting idl quietly
Next Topic: test

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

Current Time: Sun Oct 12 08:02:46 PDT 2025

Total time taken to generate the page: 0.24308 seconds