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

Home » Public Forums » archive » Re: Printing multiple columns in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Printing multiple columns in IDL [message #61771] Fri, 01 August 2008 06:01 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Joost Aan de Brugh writes:

> Now I read this thread I was wondering how I could solve my printf-
> problem. I have a procedure that prints out data in a huge 2D array. I
> cannot know beforehand how much data has to be put into the file (That
> depends on how my research is going on and if I knew that beforehand,
> it wouldn't be research). I used:
>
> dataline =3D strjoin(string(data[*,0])) ; All rows should have equal
> length
> width =3D strlen(dataline) > max(strlen(headerlines))
> openw,lun,'filename.dat',/Get_Lun,Width=3Dwidth
>
> And because my data consists of doubles and I use default format
> everywhere, I see that my width is 16 times the number of data
> columns. My width was 160. Now I wrote such a file and I see that all
> my data rows are cut at 9 values. The line is 144 long and the next
> line (containing the tenth column) is 16 long. This also happens for
> other number of columns. I tried to add one to the width for safety,
> but that does not work.
>
> Why does this not work and can anyone help me?

Weird. Have you tried using a format statement?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Printing multiple columns in IDL [message #61772 is a reply to message #61771] Fri, 01 August 2008 05:52 Go to previous messageGo to next message
Joost Aan de Brugh is currently offline  Joost Aan de Brugh
Messages: 16
Registered: July 2008
Junior Member
> This article should give you some ideas.
>
>   http://www.dfanning.com/fileio_tips/width.html
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hello David (and all others),

Now I read this thread I was wondering how I could solve my printf-
problem. I have a procedure that prints out data in a huge 2D array. I
cannot know beforehand how much data has to be put into the file (That
depends on how my research is going on and if I knew that beforehand,
it wouldn't be research). I used:

dataline = strjoin(string(data[*,0])) ; All rows should have equal
length
width = strlen(dataline) > max(strlen(headerlines))
openw,lun,'filename.dat',/Get_Lun,Width=width

And because my data consists of doubles and I use default format
everywhere, I see that my width is 16 times the number of data
columns. My width was 160. Now I wrote such a file and I see that all
my data rows are cut at 9 values. The line is 144 long and the next
line (containing the tenth column) is 16 long. This also happens for
other number of columns. I tried to add one to the width for safety,
but that does not work.

Why does this not work and can anyone help me?

Kind regards,
Joost Aan de Brugh
Re: Printing multiple columns in IDL [message #61806 is a reply to message #61772] Wed, 30 July 2008 20:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ying Wu writes:

> This is to a file using printf, and the data I'm printing is a 2-D
> array. Basically it's printf, filename, arrayname. I've also tried
> using some for loops to print each number individually but that failed
> because it puts them on top of each other.

This article should give you some ideas.

http://www.dfanning.com/fileio_tips/width.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Printing multiple columns in IDL [message #61807 is a reply to message #61806] Wed, 30 July 2008 19:59 Go to previous messageGo to next message
Ying Wu is currently offline  Ying Wu
Messages: 2
Registered: July 2008
Junior Member
On Jul 30, 7:53 pm, Chris <beaum...@ifa.hawaii.edu> wrote:
> On Jul 30, 4:18 pm, Ying Wu <ying...@gmail.com> wrote:
>
>> Hello all, I'm having a problem with printing multiple columns in
>> IDL. The data I want to print to text is 300 columns, with 141 rows.
>> Right now it's printing them all out stacked on top of each other in
>> one column.
>
> This is kind of vague- maybe an example of what you tried? Are you
> printing to the terminal using print or to a file using printf? If you
> are using printf, are you using any format codes?
>
> I would guess this is not to a terminal, since they should
> automatically word wrap long before your first row of 300 columns is
> finished.
>
> chris

This is to a file using printf, and the data I'm printing is a 2-D
array. Basically it's printf, filename, arrayname. I've also tried
using some for loops to print each number individually but that failed
because it puts them on top of each other.
Re: Printing multiple columns in IDL [message #61808 is a reply to message #61807] Wed, 30 July 2008 19:53 Go to previous messageGo to next message
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
On Jul 30, 4:18 pm, Ying Wu <ying...@gmail.com> wrote:
> Hello all, I'm having a problem with printing multiple columns in
> IDL.  The data I want to print to text is 300 columns, with 141 rows.
> Right now it's printing them all out stacked on top of each other in
> one column.

This is kind of vague- maybe an example of what you tried? Are you
printing to the terminal using print or to a file using printf? If you
are using printf, are you using any format codes?

I would guess this is not to a terminal, since they should
automatically word wrap long before your first row of 300 columns is
finished.

chris
Re: Printing multiple columns in IDL [message #61898 is a reply to message #61771] Mon, 04 August 2008 01:07 Go to previous message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
David Fanning wrote:
> Joost Aan de Brugh writes:
>> openw,lun,'filename.dat',/Get_Lun,Width=3Dwidth
> Weird. Have you tried using a format statement?

Or:

openw,lun,'filename.dat',/Get_Lun,Width=width+4


chl
Re: Printing multiple columns in IDL [message #61919 is a reply to message #61771] Fri, 01 August 2008 07:55 Go to previous message
Joost Aan de Brugh is currently offline  Joost Aan de Brugh
Messages: 16
Registered: July 2008
Junior Member
>
> Weird. Have you tried using a format statement?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Hello David,

It is becoming more and more ironic. I tried Width=width + 2 and it
works. But of course, that does not solve the problem. It only removed
the symptom. Then I used the format statement.

datalength = N_Elements(data[*,0])
printf,lun,data,format=strjoin(['(',strtrim(string(datalengt h),
2),'G16.8))'])
; The format should make no sense because it is equal to the default
format for the double array.

Though it should make no sense, it works

But even more ironic is that it also worked when I used Width=20. I
discovered that single elements are never cut.

openw,lun,'test.dat',/Get_Lun,Width=20
printf,lun,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz " ;
Far too long

It is still in one line
Adding the format statement probably converts my data into strings
(one string for a whole row) before it enters the file. And then the
file thinks it connot be cut anymore.

The 'width + 2'-thing maybe has something to do with line feeds or end-
of-lines (???)

Thanks for the help.
Joost Aan de Brugh
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Edge detection and convert edges into polygons
Next Topic: Piecewise curve fitting in idl

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

Current Time: Fri Oct 10 14:26:18 PDT 2025

Total time taken to generate the page: 1.68214 seconds