Re: idl format codes and output files [message #58915] |
Mon, 25 February 2008 10:50  |
Kenneth Bowman
Messages: 86 Registered: November 2006
|
Member |
|
|
In article <82c65103-bb37-4cf3-af12-d060e5ae30d8@o10g2000hsf.googlegroups.com>,
elwood <epolomsk@uwsp.edu> wrote:
> Is there a way to use printf and a format code which takes as a
> parameter a variable size
> width that is calculated prior to calling printf.
> Reason why: So that the output file will have pretty formatted
> columns.
>
>
> For example,
> Suppose I have a program that prompts for a string.
> The program doesnt know ahead of time how long the string will be.
>
> Then I use strlen to find its length
> len=strlen(word)
>
> can I do something like the following:
>
> printf,1,word,format='(alen)'
A format code is just a string itself, so you can create the format
in may ways, e.g.,
IDL> len = 20
IDL> format = '(A' + STRTRIM(len, 2) + ')'
IDL> print, format
(A20)
IDL> PRINT, 'This is a test string.', FORMAT = format
This is a test strin
Ken Bowman
|
|
|
Re: idl format codes and output files [message #58916 is a reply to message #58915] |
Mon, 25 February 2008 13:25  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Feb 25, 1:36 pm, Bob Crawford <Snowma...@gmail.com> wrote:
> On Feb 25, 1:16 pm, elwood <epolo...@uwsp.edu> wrote:
>
>> Is there a way to use printf and a format code which takes as a
>> parameter a variable size
>> width that is calculated prior to calling printf.
>> Reason why: So that the output file will have pretty formatted
>> columns.
>
>> For example,
>> Suppose I have a program that prompts for a string.
>> The program doesnt know ahead of time how long the string will be.
>
>> Then I use strlen to find its length
>> len=strlen(word)
>
>> can I do something like the following:
>
>> printf,1,word,format='(alen)'
>
> printf,1,word,format='(a)'
>
> -or-
>
> printf,1,word,fromat='(a0)'
To be more precise, yes you can create a string and pass it to the
format keyword. For example:
read, iwid, prompt="Input width: "
fmt='(I' + strtrim(iwid,2) + ')'
printf, lun, val, format=fmt
|
|
|
Re: idl format codes and output files [message #58918 is a reply to message #58915] |
Mon, 25 February 2008 11:36  |
Bob[3]
Messages: 60 Registered: December 2006
|
Member |
|
|
On Feb 25, 1:16 pm, elwood <epolo...@uwsp.edu> wrote:
> Is there a way to use printf and a format code which takes as a
> parameter a variable size
> width that is calculated prior to calling printf.
> Reason why: So that the output file will have pretty formatted
> columns.
>
> For example,
> Suppose I have a program that prompts for a string.
> The program doesnt know ahead of time how long the string will be.
>
> Then I use strlen to find its length
> len=strlen(word)
>
> can I do something like the following:
>
> printf,1,word,format='(alen)'
printf,1,word,format='(a)'
-or-
printf,1,word,fromat='(a0)'
|
|
|