0

I want to print to file in IDL. The number of files exceeds 100 and I can only ever get 100 text files produced.

My code is:

for i = 0,575 do begin
fname='file_'+string(i,format="(i03)")+'.txt'
openw,21+i,fname,/append
for j = 1,nchan(0)-1 do begin
printf,21+i,chvel(0,j)/1.e5,s1(j,i),FORMAT='(F9.4,2X,F9.4)'
endfor
close,21+i
endfor
stars83clouds
  • 795
  • 1
  • 8
  • 25

1 Answers1

2

Simple solution - use free_lun. Only 100 logical unit numbers can be used at any one time, free_lun lets you re-use those LUN's available to you.

for i = 0,575 do begin
fname='file_'+string(i,format="(i03)")+'.txt'
openw,lun,fname,/get_lun,/append
for j = 1,nchan(0)-1 do begin
printf,lun,chvel(0,j)/1.e5,s1(j,i),FORMAT='(F9.4,2X,F9.4)'
endfor
close,lun
free_lun,lun
endfor
stars83clouds
  • 795
  • 1
  • 8
  • 25
  • 1
    The other key here is the use of `/get_lun` in the `openw` command. – sappjw Mar 20 '14 at 13:06
  • Well, that and that you should be using []'s instead of ()'s to index arrays. In later versions of IDL, this can be an issue unless you specify the compile options inside routines. – honeste_vivere Sep 28 '14 at 15:52