X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 15 Mar 2018 12:28 PM by  David Starbuck
How to write structure to file with printf without carriage returns
 0 Replies
Sort:
You are not authorized to post a reply.
Author Messages

David Starbuck



Basic Member


Posts:143
Basic Member


--
15 Mar 2018 12:28 PM
    Question:
    A user has asked us how to write data from a structure to a file using printf. without carriage returns being added to the middle of a record.

    Answer:
    If you run the following commands, it print the structure to a file with carriage returns:

    IDL> A = {star, name:'Hello There!', ra:2.0, dec:3.0, inten:FLTARR(12)+4.0}
    IDL> openw, 1, "test_struct_output.txt"
    IDL> printf, 1, A
    IDL> free_lun, 1

    On way to workaround this issue is to use the FORMAT keyword to specify that all the elements within a structure are written to the same line. For example:

    IDL> A = {star, name:'Hello There!', ra:2.0, dec:3.0, inten:FLTARR(12)+4.0}
    IDL> printf, 1, A, FORMAT='(50A)'
    IDL> free_lun, 1

    Where the in the "(50A)' format, the '50' should be any number that is greater than the number of elements in the structure

    David S.
    -HGS.
    You are not authorized to post a reply.