[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing formatted text files
- Subject: Re: Writing formatted text files
- From: "Liam Gumley" <Liam.Gumley(at)ssec.wisc.edu>
- Date: Fri, 11 Feb 2000 15:35:44 -0600
- Newsgroups: comp.lang.idl-pvwave
- Organization: University of Wisconsin, Madison
- References: <38A47BCA.884D0CC@va.aetc.com>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:18400
Bernard Puc <bpuc@va.aetc.com> wrote in message
38A47BCA.884D0CC@va.aetc.com">news:38A47BCA.884D0CC@va.aetc.com...
> 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
This doesn't get rid of all the whitespace, but it's simple and quick, and
the output is easy to read:
arr = findgen(3, 1000) * 0.1
print, arr, format='(2(f8.3, ","),f8.3)'
Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley