Re: Writing CSV files? [message #37606 is a reply to message #37522] |
Thu, 08 January 2004 01:46  |
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
>
> [...]
|
|
|