Question

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
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top