Re: Dynamic format. [message #50293] |
Tue, 26 September 2006 16:12 |
Hanford
Messages: 2 Registered: September 2006
|
Junior Member |
|
|
Thanks Ben. Worked well.
Hanford.
Ben Tupper wrote:
> hanford.deglint@gmail.com wrote:
>> Dynamic format.
>>
>> Hello.
>>
>> The following little program fails.
>>
>> pro temp
>>
>> cols = 120
>> a = indgen(cols,12)
>>
>> openw, /get_lun, unit, '~/temp/whatever.dat'
>> printf, unit, a, fomat = '(colsI)'
>>
>> free_lun, unit
>>
>> end
>>
>> This is not working. It seems that format requires a number, it does
>> not like cols. Is there a way to format this text in such a way the
>> carriage return is at the end of the row. Using 'printf, unit, a'
>> causes the carriage return to be interspersed and at the end.
>>
>
> Hello,
>
> Your trying to smush an integer into a string without converting it
> first. I think you want something like,
>
> printf,unit,a, format='(' + STRTRIM(cols,2) + 'I)'
>
> which converts cols to STRING first.
>
> I am not sure if it is an issue for you but you may need to specify the
> WIDTH keyword to OPENW. Sometimes the default width isn't quite wide
> enough.
>
> Cheers,
> Ben
|
|
|
Re: Dynamic format. [message #50296 is a reply to message #50293] |
Tue, 26 September 2006 14:16  |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
hanford.deglint@gmail.com wrote:
> Dynamic format.
>
> Hello.
>
> The following little program fails.
>
> pro temp
>
> cols = 120
> a = indgen(cols,12)
>
> openw, /get_lun, unit, '~/temp/whatever.dat'
> printf, unit, a, fomat = '(colsI)'
>
> free_lun, unit
>
> end
>
> This is not working. It seems that format requires a number, it does
> not like cols. Is there a way to format this text in such a way the
> carriage return is at the end of the row. Using 'printf, unit, a'
> causes the carriage return to be interspersed and at the end.
>
Hello,
Your trying to smush an integer into a string without converting it
first. I think you want something like,
printf,unit,a, format='(' + STRTRIM(cols,2) + 'I)'
which converts cols to STRING first.
I am not sure if it is an issue for you but you may need to specify the
WIDTH keyword to OPENW. Sometimes the default width isn't quite wide
enough.
Cheers,
Ben
|
|
|