X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 06 Dec 2011 07:50 AM by  anon
append write_csv or grow matrix in loop?
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
06 Dec 2011 07:50 AM
    Hi there, I was wondering if there is such a function as to append write to a .txt or .csv? What I mean is that if I have a loop that calculates a value, can I write that value to the same .txt or .csv file without over writing the previous entry? I tried the writeu function but i dont want binary and couldnt see how to convert it to ascii. Or if there is a way to grow a matrix inside of a loop? Then I can just write the matrix outside of the loop all in 1 go. I know Matlab can do such a thing easily. For example what I would like to do is: i = 3 for i= 0,i-1 do begin a = 2*i b {i} = a ;this is matlab syntax and creates a cell matrix that will grow with each iteration is there such a thing in IDL? endfor I googled but didnt find what i was looking for. i also searched the help to no avail

    Deleted User



    New Member


    Posts:
    New Member


    --
    06 Dec 2011 08:50 AM
    edit** i changed the original post subject to include the part about matrices I'm so silly. just needed to preallocate the matrix and then i can add values to the matrix. i = 3 b = DCINDGEN(i) for i= 0,i-1 do begin a = 2*i b[i] = a endfor still curious on the append to csv or txt file...

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 Dec 2011 09:53 AM
    To append to a csv or a txt file, you can open the file using the OPENW or OPENU routines with the APPEND keyword. Then you can write to the file using the PRINTF routine. A short example, is included below: pro ex_append_txt COMPILE_OPT IDL2 ;Quick example openw, lun, "FishRfun.txt", /GET_LUN ; create the file printf,lun, "Top of FishRfun file!" printf,lun, "Closing File!" free_lun, lun ;close the file openu, lun, "FishRfun.txt", /GET_LUN, /APPEND ;reopen file to read and write with Append keyword printf, lun, "File reopened with APPEND keyword!" i = 3 b = FINDGEN(i) for i= 0,i-1 do begin a = 2*i b[i] = a*2 printf, lun, a, " ", b ; write the variable values to the end of the file endfor free_lun, lun ; closes the file end

    Deleted User



    New Member


    Posts:
    New Member


    --
    31 Jul 2014 12:11 PM
    Is is possible to do this with image or binary files also?
    You are not authorized to post a reply.