Search code examples
idl-programming-language

Writing to a file in IDL


I am writing to a file in IDL. The file is written to after analysing data from the run of a code. I plan to run the code more than once, and collect the data into the same file after each run. How can I use IDL to do this? I implemented some code, but the data is just updated after each run. There is no recording of individual data.

fname='ratios.dat'
if (k eq 0) then begin
openw,21,fname
printf,21,Ratio_02,Ratio_12,FORMAT='(F6.4,2X,F6.4)'
endif else begin
openu,21,fname
printf,21,Ratio_02,Ratio_12,FORMAT='(F6.4,2X,F6.4)'
endelse

k is the iterating variable which has more than one value at a higher nested loop. The purpose of openu was my attempt to update the already produced file with additional data.


Solution

  • This is possible if you use the /append keywork as part of the openw syntax and closing the file each time, viz:

    fname='ratios.dat'
    openw,21,fname,/append
    printf,21,Ratio_02,Ratio_12,FORMAT='(F6.4,2X,F6.4)'
    close,21