Re: Q: Use of variables with FORMAT [message #7832] |
Thu, 09 January 1997 00:00 |
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
|
|
|