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 #94592 is a reply to message #94590] Tue, 18 July 2017 06:42 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Tuesday, July 18, 2017 at 9:12:18 AM UTC-4, 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.
>

Problem 1. You need to use "straight" quotes. You are using something like Microsoft word or some notepads that use curly quotes. IDL uses straight quotes.

Problem 2. The string 'File_'+i+'.dat' won't work because you are combining an integer and string. You could use 'File_'+strtrim(i,2)+'.dat' or use STRING() with a FORMAT= argument.

Problem 3. You are using GET_LUN once at the top of your loop and again for each loop. You never close any files. Use FREE_LUN at the end of your loop.

CM
[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: Sat Oct 11 21:09:18 PDT 2025

Total time taken to generate the page: 1.20293 seconds