[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing formatted text files



Hi all,

	I'd like to speed-up the following code.  I'm writing comma delimited
text files, I'm eliminating whitespace by using strtrim, and am
explicitly formatting the string using a format keyword.  Any ideas how
to improve this?  I've been playing with various ways of formatting
without using a FOR loop but either don't get the desired output or the
error message telling me the output string has been truncated to 1024
lines.

data_to_write = fltarr(3, 100000)
FOR j=0, 99999 DO BEGIN
  PRINTF,Lun,$
    strtrim(string(data_to_write[0,j],format='(f10.3)'),2),',',$
    strtrim(string(data_to_write[1,j],format='(f10.3)'),2),',',$
    strtrim(string(data_to_write[2,j],format='(f10.3)'),2),$
    FORMAT = "(a,a,a,a,a)"
ENDFOR

Output should look like this:

278.980,-232.018,258.090
278.926,-231.974,258.360
278.889,-231.944,241.240
278.852,-231.913,206.900
278.814,-231.883,156.390
278.776,-231.852,93.680
278.739,-231.821,27.799
278.702,-231.791,-33.771
278.664,-231.760,-84.551
278.626,-231.729,-121.161  
...

Thanks.

-- 
Bernard Puc                     AETC, INC.									  
bpuc@va.aetc.com                1225 Jefferson Davis Highway #800
(703) 413-0500                  Arlington, VA 22202