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

Home » Public Forums » archive » Re: Writing CSV files?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Writing CSV files? [message #37606 is a reply to message #37522] Thu, 08 January 2004 01:46 Go to previous message
Timm Weitkamp is currently offline  Timm Weitkamp
Messages: 66
Registered: August 2002
Member
Format codes provide a convenient way of bringing numbers in IDL into
shape for output to screen or files (see also "Format Codes" in the online
help). Why not use them in a WRITE_CSV routine, like this simple one:

PRO write_csv, fileName, data

nColumns = (SIZE(data))[1]
formatStr = '(' + STRTRIM(nColumns,2) + '(F, :,", "))'

OPENW, u, fileName, /GET_LUN, WIDTH=1000
PRINTF, u, data, FORMAT=formatStr
FREE_LUN, u

END

If the data arrays you want to write are very large, then you may want to
replace the single "PRINTF, ..." line above by a FOR loop to avoid memory
problems:

[...]
OPENW, u, fileName, /GET_LUN, WIDTH=1000
nRows = (SIZE(data))[2]
FOR iRow = 0, nRows-1 DO BEGIN
thisRow = STRING(data[*,iRow], FORMAT=formatStr)
PRINTF, u, thisRow
ENDFOR
FREE_LUN, u
[...]

Hope this helps,

Timm

--
Timm Weitkamp <http://people.web.psi.ch/weitkamp>


On 06.01.04 at 15:12 -0700, David Fanning wrote:

> Jonathan Greenberg writes:
>
>> Is there an easy way to write an array to an ASCII comma deliminated file
>> (CSV)? I see a READ_ASCII command but no WRITE_ASCII. Thanks!
>
> Here is an article that discusses one way to do this:
>
> http://www.dfanning.com/tips/csv_file.html
>
> [...]
[Message index]
 
Read Message
Read Message
Previous Topic: Maximum likelihood question (ENVI)
Next Topic: Writing CSV files?

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

Current Time: Thu Oct 09 21:35:27 PDT 2025

Total time taken to generate the page: 0.63734 seconds