Re: Writing 2D array to Text File [message #67757] |
Fri, 21 August 2009 13:47 |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Aug 21, 2:56 pm, Vikram <vikramivat...@gmail.com> wrote:
> Is there anyway that I can format my PRINTF to print 120 columns and
> 120 rows, for viewing in Excel. Any ideas?
If you are using IDL 7.1, you can also use write_csv to do everything
(not just in place of printf, but in place of openw,printf,free_lun/
close), as in:
write_csv,'file.csv',array
|
|
|
Re: Writing 2D array to Text File [message #67759 is a reply to message #67757] |
Fri, 21 August 2009 13:40  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Aug 21, 4:09 pm, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> you can play with the format keyword...
> something like this:
>
> print, a, format='(120(A,","))' ==> will put a comma after each value
>
> or
>
> print, a, format='(120A)' ==>will write by 120 cols.
>
> So, in your case, just remove the loops...
>
> PRINTF,lun,array, format = '(120A)'
That is in case it is an array of strings. For numbers you would have
to pick a numeric format in place of the A (I,F,E being the most
common; see the documentation on print, and there will be a link to
the format codes).
That double loop was writing only one element per line because by
default each printf statement moves the output to a new line after it,
so it was putting a newline after each element.
|
|
|
Re: Writing 2D array to Text File [message #67762 is a reply to message #67759] |
Fri, 21 August 2009 12:09  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Vikram wrote:
> Hello IDL Gurus,
>
> I would like to write a 2D array that I have [120,120], to a text
> file. When I write the array out now, everything appears in 1 column
> with 14400 rows:
>
> for i = 0,119 do begin
> for j = 0,119 do begin
> PRINTF,lun,array[i,j]
> endfor
> endfor
>
> Is there anyway that I can format my PRINTF to print 120 columns and
> 120 rows, for viewing in Excel. Any ideas?
>
> Thanks,
> Vikram
Vikram,
you can play with the format keyword...
something like this:
print, a, format='(120(A,","))' ==> will put a comma after each value
or
print, a, format='(120A)' ==>will write by 120 cols.
So, in your case, just remove the loops...
PRINTF,lun,array, format = '(120A)'
You can even change the 120 by n_elements(array[*,0]) etc
Jean
|
|
|