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

Home » Public Forums » archive » Writing to Multiple txt file with different names
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Writing to Multiple txt file with different names [message #94591 is a reply to message #94590] Tue, 18 July 2017 06:40 Go to previous messageGo to previous message
Jim  Pendleton is currently offline  Jim Pendleton
Messages: 165
Registered: November 2011
Senior Member
On Tuesday, July 18, 2017 at 7:12:18 AM UTC-6, thtr...@gmail.com wrote:
> Hello everybody,
>
> I need to write my data to a bunch of different files, ideally with 'consecutive' names, such as File 1, File 2, File 3, .. so on (up to thousands of text files)
>
> Here's my attempt:
>
> get_lun, unit
> for i = 1,1000 do begin
> openw, unit, ‘File_’+ i + ‘.dat’, /get_lun
> printf, unit, 'my data will go in here'
> endfor
>
> IDL keeps saying filename argument must be a scalar string.
> Any help would be appreciated.
>
> Thank you.

Try
openw, unit, ‘File_’+ i.tostring() + ‘.dat’, /get_lun

or if you're using an older version of IDL,
openw, unit, ‘File_’+ strtrim(i, 2) + ‘.dat’, /get_lun

The reason is that when the interpreter sees the "+" and a number, it will up-cast the other arguments in the expression to the highest precedence, rather than converting integers to strings.

Compare and contrast:
IDL> i = 10 & help, 'file_' + i + '.dat'
% Type conversion error: Unable to convert given STRING to Integer.
% Detected at: $MAIN$
% Type conversion error: Unable to convert given STRING to Integer.
% Detected at: $MAIN$
<Expression> INT = 10

IDL> i = 10 & help, '1' + i + '3'
<Expression> INT = 14

IDL> i = 10 & help, '1' + i + 30.0
<Expression> FLOAT = 41.0000

Jim P
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Plot scatter points with transparency
Next Topic: Auto-path finding when writing file

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

Current Time: Wed Oct 08 15:57:17 PDT 2025

Total time taken to generate the page: 0.00224 seconds