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

Home » Public Forums » archive » Re: Format in PRINTF
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Format in PRINTF [message #45648] Tue, 27 September 2005 06:10
coco is currently offline  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 Go to previous message
David Fanning is currently offline  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 Go to previous message
btt is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: USERSYM filled AND outlined?
Next Topic: How to disable "auto debug mode" in idlwave?

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

Current Time: Wed Oct 08 11:40:20 PDT 2025

Total time taken to generate the page: 0.00569 seconds