Re: Format in PRINTF [message #45648] |
Tue, 27 September 2005 06:10 |
coco
Messages: 2 Registered: September 2005
|
Junior Member |
|
|
Hi Ben,
I think you got my problem. When i use the strtrim command, it is
working :))
Thanks a lot!!!
Cheers,
corinne
|
|
|
Re: Format in PRINTF [message #45649 is a reply to message #45648] |
Tue, 27 September 2005 05:59  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
coco writes:
> I have a stringarray containing numbers and letters and want to print
> this string to a file. each line should consist of 130 arrayelements,
> each element should take two places.
>
> Using this format command: format='(130(A2))' just writes the letters,
> but not the numbers.
>
> Anybody an idea???
Sorry, but I'm not buying:
IDL> a=['rt','56','gu','32','h5','i9']
IDL> print, a, format='(6(A2))'
rt56gu32h5i9
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Format in PRINTF [message #45650 is a reply to message #45649] |
Tue, 27 September 2005 05:56  |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
coco wrote:
> Hi,
>
> I have a stringarray containing numbers and letters and want to print
> this string to a file. each line should consist of 130 arrayelements,
> each element should take two places.
>
> Using this format command: format='(130(A2))' just writes the letters,
> but not the numbers.
>
Hi,
Believe it or not - your numbers are being output - but they are being
truncated, too.
IDL> v = 18
IDL> s = STRING(v)
IDL> print, v
18
IDL> print, s
18
The 'natural' length of an integer converted to a string is 8
characters. Note that the integer-now-string is padded on the left with
spaces. Anytime you specify the output format with '(A2)' then just the
first two characters are output and the rest is truncated.
IDL> v = '1234'
IDL> print, v, FORMAT = '(A2)'
12
Where to go from here depends on what you need to do. Since you have a
string array to start with you might try STRTRIM(value, 2) which strips
leading and trailing blanks.
IDL> v = STRING(18)
IDL> s = STRTRIM(v, 2)
IDL> print, v
18
IDL> print, s
18
Make sure you have a plan for when the numbers exceed two digits in length.
Cheers,
Ben
|
|
|