comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Use Ascii_Template/Read_Ascii results to write a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Use Ascii_Template/Read_Ascii results to write a file [message #87505] Sun, 09 February 2014 20:56
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Say I have a template and structure returned by Ascii_Template() and Read_Ascii(), respectively. In general, I do not know how many fields the structure has. I now want to turn around and write the data to a file. Is there a way to do this without a double loop?

pro test_write_ascii
compile_opt strictarr

;Information available from Ascii_Template and Read_Ascii
str_fmt = ['i', 'a']
nLines = 4
nFields = 2

;Structure returned by Read_Ascii()
struct = {field0: [0,1,2,3], $
field1: ['a', 'b', 'c', 'd']}

;Open a file
openw, lun, '/test.txt', /get_lun

;Loop through each data point
for i = 0, nLines - 1 do begin

;Make a comma-delimited string
str_field = ''
for j = 0, nFields - 1 do str_field += String( struct.(j)[i], FORMAT='(' + str_fmt[j] + ')' ) + ','

;Print the string to the file
printf, lun, str_field
endfor

free_lun, lun
end



I also tried

myList = List([0,1,2,3], ['a', 'b', 'c', 'd'])
Print, myList

but the list prints horizontally, not vertically, which is what I am after.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDLDE questions
Next Topic: correlation coefficient and confidence level

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:55:21 PDT 2025

Total time taken to generate the page: 0.00484 seconds