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

Home » Public Forums » archive » Re: maximum line length with printf?
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: maximum line length with printf? [message #44659] Fri, 08 July 2005 08:16 Go to next message
guillaume.drolet.1 is currently offline  guillaume.drolet.1
Messages: 20
Registered: July 2005
Junior Member
Thanks all for your replies.

Ben's suggestion of adding the 'WIDTH=500' keyword to 'openw' worked
fine.

My output file has all seven variables on the same line.

Yahoo!!!

Gui
Re: maximum line length with printf? [message #44669 is a reply to message #44659] Thu, 07 July 2005 13:41 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Nonsense, works fine with arrays: Try
print,findgen(10),100,format='(11f8.2)'

Haje

<francesca_terenzi@yahoo.it> wrote in message
news:1120767202.505829.66730@z14g2000cwz.googlegroups.com...
> Yes, using the format keyword is exactly what I was suggesting to do in
> first place, but badly...!!!!
> In any case, I think that should not work either if one of the
> variables is not an array and if he is using a loop.
> alternatively, he can avoid using the loop at all and just write:
>
> openw,unit,fileout
> printf,data[0],data[1],data[2],data[3],data[4],data[5],doy,
> format='(....)'
> where inside the parentesis he will put the right formatting for each
> and everyone of the data...
>
> actually, i think avoidind the loop will work also if he puts that doy
> data at the end.....
>
> bye bye
>
Re: maximum line length with printf? [message #44670 is a reply to message #44669] Thu, 07 July 2005 13:13 Go to previous messageGo to next message
francesca_terenzi is currently offline  francesca_terenzi
Messages: 8
Registered: July 2005
Junior Member
Yes, using the format keyword is exactly what I was suggesting to do in
first place, but badly...!!!!
In any case, I think that should not work either if one of the
variables is not an array and if he is using a loop.
alternatively, he can avoid using the loop at all and just write:

openw,unit,fileout
printf,data[0],data[1],data[2],data[3],data[4],data[5],doy,
format='(....)'
where inside the parentesis he will put the right formatting for each
and everyone of the data...

actually, i think avoidind the loop will work also if he puts that doy
data at the end.....

bye bye
Re: maximum line length with printf? [message #44671 is a reply to message #44670] Thu, 07 July 2005 12:58 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Alternatively you can uise formatted output suing the FORMAT keyword to
printf. Haje


"Ben Tupper" <btupper@bigelow.org> wrote in message
news:3j5eodFod6nrU1@individual.net...
> guillaume.drolet.1@ulaval.ca wrote:
>> Hi all IDL users!
>>
>> I'm currently writing formatted file with IDL using the printf
>> function.
>> I want to have my 7 variables on the same line:
>>
>> printf, lun_1,
>> data[0,m],data[1,m],data[2,m],data[3,m],data[4,m],data[5,m], doy
>>
>> In my output file, the last variable is on the next line, apart from
>> the 6 other variables. Then the loop goes on and it starts a new line
>> with only the first 6 variables and another one with only the seventh,
>> etc...
>>
>> Is the printf function retrained in terms of line length or number of
>> characters?
>>
>> Thanks for helping on this. It is pretty annoying and not the first
>> time I'm running into this problem with IDL.
>>
>> Gui
>>
>
> Hello,
>
> I think you might need to specify the WIDTH keyword when you OPEN the
> file. Try something big like 500.
>
> Ben
Re: maximum line length with printf? [message #44672 is a reply to message #44671] Thu, 07 July 2005 12:55 Go to previous messageGo to next message
francesca_terenzi is currently offline  francesca_terenzi
Messages: 8
Registered: July 2005
Junior Member
Ooops...

I've just notices that you last variable: '­doy" is not an array,
while all the other 5 are. Is that right?
I think in this case what I've said above will not work either.
I am not awared of what Ben told you above, but if that does not work
either, ...here is anoother idea...
Why do not you save the "doy" variable separately from the other data?
I mean, something like:

openw,1,fileout
printf,1,doy
for m=0,M-1 do begin
prinft,1,data[0,m],data[1,m],data[2,m],­data[3,m],data[4,m] ,data[5,m]
endfor
close,1
Re: maximum line length with printf? [message #44673 is a reply to message #44672] Thu, 07 July 2005 12:45 Go to previous messageGo to next message
francesca_terenzi is currently offline  francesca_terenzi
Messages: 8
Registered: July 2005
Junior Member
Hi Guillaume,
in my little experience with IDL I have noticed that if I want to save
a file with more than 6 different variables (i.e starting from the
seventh),
in that case I have to format them.
For example, you have to tell IDL that you want the first data to be -
say - an integer with 4 digits, the second one to be a real number with
1 decimal digit after the comma, and so on so forth...
I do not know if there a way to avoid that, but check on the HELP..Look
for the "printf" commanda and then look for "Using Explicitly Formatted
Input/Output" explanation...
Do not know if this helped at all or not....
Bye
Francesca
Re: maximum line length with printf? [message #44674 is a reply to message #44673] Thu, 07 July 2005 12:39 Go to previous messageGo to next message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
guillaume.drolet.1@ulaval.ca wrote:
> Hi all IDL users!
>
> I'm currently writing formatted file with IDL using the printf
> function.
> I want to have my 7 variables on the same line:
>
> printf, lun_1,
> data[0,m],data[1,m],data[2,m],data[3,m],data[4,m],data[5,m], doy
>
> In my output file, the last variable is on the next line, apart from
> the 6 other variables. Then the loop goes on and it starts a new line
> with only the first 6 variables and another one with only the seventh,
> etc...
>
> Is the printf function retrained in terms of line length or number of
> characters?
>
> Thanks for helping on this. It is pretty annoying and not the first
> time I'm running into this problem with IDL.
>
> Gui
>

Hello,

I think you might need to specify the WIDTH keyword when you OPEN the
file. Try something big like 500.

Ben
Re: maximum line length with printf? [message #44744 is a reply to message #44672] Sun, 10 July 2005 23:48 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
francesca_terenzi@yahoo.it wrote:
> Ooops...
>
> I've just notices that you last variable: '�doy" is not an array,
> while all the other 5 are. Is that right?
> I think in this case what I've said above will not work either.
> I am not awared of what Ben told you above, but if that does not work
> either, ...here is anoother idea...
> Why do not you save the "doy" variable separately from the other data?
> I mean, something like:
>
> openw,1,fileout
> printf,1,doy
> for m=0,M-1 do begin
> prinft,1,data[0,m],data[1,m],data[2,m],�data[3,m],data[ 4,m],data[5,m]
> endfor
> close,1
>



You should better use
openw,lun,/get_lun, filename

and at the end

free_lun,lun

Because then you don't get into the trouble if somewhere a fixed unit is
already in usage.

If you add width as keyword you can setup a longer width as the detault one.


I am not sure what the loop is used for. Didn't you get the same result
by prinft,lun,data. Probably you only need to transpose?


Idl does not be case sensitive so you see me a bit surprised that's this
work. I would have bet against this

m=5
for m=0,M-1 do begin

For better coding I would suggest to rename M to n_from_what_it_is, and
to use i as increment var. But that's a question of reading/writing style.

cheers

Reimar

--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Announcing GDL 0.8.10
Next Topic: Giving Up on Windows

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

Current Time: Wed Oct 08 13:51:34 PDT 2025

Total time taken to generate the page: 0.04229 seconds