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

Home » Public Forums » archive » How to plot multiple charts and ho to round float to specific precision?
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
How to plot multiple charts and ho to round float to specific precision? [message #44858] Wed, 27 July 2005 06:48 Go to next message
liko2@o2.pl is currently offline  liko2@o2.pl
Messages: 15
Registered: July 2005
Junior Member
Hi :)

1. How to plot multiple plots (eg 8-10 on one page of A4) but not using
multiplot?
2. How to round float eg. 23,45654 to 23,46?

THX for answer :)
Re: How to plot multiple charts and ho to round float to specific precision? [message #44957 is a reply to message #44858] Thu, 28 July 2005 17:54 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
BTW:

IDL> print,!version
{ x86 linux unix linux 6.1.1 Oct 11 2004 32 64}
IDL> x=23.45654
IDL> cx=string(x,format='(f0.2)')
IDL> help,cx
CX STRING = '23.46'
IDL> y=7140264.38264
IDL> cy=string(y,format='(f0.2)')
IDL> help,cy
CY STRING = '7140264.50'
IDL>

Maybe it was a bug in IDL 6.0.x ...

Benjamin
Re: How to plot multiple charts and ho to round float to specific precision? [message #44958 is a reply to message #44858] Thu, 28 July 2005 17:52 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Paul Van Delst wrote:
> Benjamin Hornberger wrote:
>
>>
>> Can't you just use a "0" in the format string ('(f0.2)') instead of
>> using a large number first and then trimming the string?
>
>
> I tried that first (based on your original post) but it didn't work for me.
>
> IDL> print, !version
> { x86 linux unix linux 6.0.3 Feb 26 2004 32 64}
> IDL> x=23.45654
> IDL> cx=string(x,format='(f0.2)')
> IDL> help, cx
> CX STRING = '23.456539'
> IDL> y=7140264.38264
> IDL> cy=string(y,format='(f0.2)')
> IDL> help, cy
> CY STRING = '7140264.500000'
>
> Dunno why not.
>
> paulv
>

IDL> print, !version
{ x86 Win32 Windows Microsoft Windows 6.1.1 Oct 11 2004 32 64}
IDL> x=23.45654
IDL> cx=string(x,format='(f0.2)')
IDL> help,cx
CX STRING = '23.46'
IDL> y=7140264.38264
IDL> cy=string(y,format='(f0.2)')
IDL> help,cy
CY STRING = '7140264.50'

Bug or feature?

Benjamin
Re: How to plot multiple charts and ho to round float to specific precision? [message #44959 is a reply to message #44858] Thu, 28 July 2005 15:45 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Benjamin Hornberger wrote:
> Paul Van Delst wrote:
>
>> liko2@o2.pl wrote:
>>
>>> No, it has to be a value of variable, later used for a part of title of
>>> a chart. So it has to be exact value with only 2 digits after zero.
>>>
>>
>> Given your floating point variable,
>>
>> IDL> x=23.45654
>> IDL> print, x
>> 23.4565
>>
>> you can stick it into a string variable
>>
>> IDL> cx=string(x,format='(f15.2)')
>> IDL> help, cx
>> CX STRING = ' 23.46'
>>
>> Note I used the format f15.2 since you might have a number like
>>
>> IDL> y=7140264.38264
>> IDL> cy=string(y,format='(f15.2)')
>> IDL> help, cy
>> CY STRING = ' 7140264.38'
>>
>> You'll want to leave enough room up front (via the "15" in f15.2) for
>> the extra digits.
>>
>> And then you can crop the above results to your heart's content:
>>
>> IDL> help, strtrim(cx,2), strtrim(cy,2)
>> <Expression> STRING = '23.46'
>> <Expression> STRING = '140264.38'
>>
>> for your plot titles.
>>
>> paulv
>>
>
> Can't you just use a "0" in the format string ('(f0.2)') instead of
> using a large number first and then trimming the string?

I tried that first (based on your original post) but it didn't work for me.

IDL> print, !version
{ x86 linux unix linux 6.0.3 Feb 26 2004 32 64}
IDL> x=23.45654
IDL> cx=string(x,format='(f0.2)')
IDL> help, cx
CX STRING = '23.456539'
IDL> y=7140264.38264
IDL> cy=string(y,format='(f0.2)')
IDL> help, cy
CY STRING = '7140264.500000'

Dunno why not.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: How to plot multiple charts and ho to round float to specific precision? [message #44960 is a reply to message #44858] Thu, 28 July 2005 15:41 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
liko2@o2.pl wrote:
> No, it has to be a value of variable, later used for a part of title of
> a chart. So it has to be exact value with only 2 digits after zero.
>

Does it have to be a numerical variable (which you still need for
calculations) or a string variable? In the former case, just round it as
described by other people and format it when you output it. If you need
a string variable, use the STRING function with the FORMAT keyword as I
described (the FORMAT keyword works the same for the STRING function and
the PRINT procedure).

Benjamin
Re: How to plot multiple charts and ho to round float to specific precision? [message #44961 is a reply to message #44858] Thu, 28 July 2005 15:38 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Paul Van Delst wrote:
> liko2@o2.pl wrote:
>
>> No, it has to be a value of variable, later used for a part of title of
>> a chart. So it has to be exact value with only 2 digits after zero.
>>
>
> Given your floating point variable,
>
> IDL> x=23.45654
> IDL> print, x
> 23.4565
>
> you can stick it into a string variable
>
> IDL> cx=string(x,format='(f15.2)')
> IDL> help, cx
> CX STRING = ' 23.46'
>
> Note I used the format f15.2 since you might have a number like
>
> IDL> y=7140264.38264
> IDL> cy=string(y,format='(f15.2)')
> IDL> help, cy
> CY STRING = ' 7140264.38'
>
> You'll want to leave enough room up front (via the "15" in f15.2) for
> the extra digits.
>
> And then you can crop the above results to your heart's content:
>
> IDL> help, strtrim(cx,2), strtrim(cy,2)
> <Expression> STRING = '23.46'
> <Expression> STRING = '140264.38'
>
> for your plot titles.
>
> paulv
>

Can't you just use a "0" in the format string ('(f0.2)') instead of
using a large number first and then trimming the string?

Benjamin
Re: How to plot multiple charts and ho to round float to specific precision? [message #44966 is a reply to message #44858] Thu, 28 July 2005 09:30 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
liko2@o2.pl wrote:
> No, it has to be a value of variable, later used for a part of title of
> a chart. So it has to be exact value with only 2 digits after zero.
>

Given your floating point variable,

IDL> x=23.45654
IDL> print, x
23.4565

you can stick it into a string variable

IDL> cx=string(x,format='(f15.2)')
IDL> help, cx
CX STRING = ' 23.46'

Note I used the format f15.2 since you might have a number like

IDL> y=7140264.38264
IDL> cy=string(y,format='(f15.2)')
IDL> help, cy
CY STRING = ' 7140264.38'

You'll want to leave enough room up front (via the "15" in f15.2) for the extra digits.

And then you can crop the above results to your heart's content:

IDL> help, strtrim(cx,2), strtrim(cy,2)
<Expression> STRING = '23.46'
<Expression> STRING = '140264.38'

for your plot titles.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: How to plot multiple charts and ho to round float to specific precision? [message #44968 is a reply to message #44858] Thu, 28 July 2005 08:46 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
liko2@o2.pl wrote:
> No, it has to be a value of variable, later used for a part of title of
> a chart. So it has to be exact value with only 2 digits after zero.

If the only thing you're going to do with the variable is print it as
part of a title of a chart, isn't it sufficient to know how to print it
with only 2 digits after zero? Are there any calculations you intend to
perform, where it's important to use the rounded value, rather than the
exact value, in those calculations? I've seen situations where
something like that was actually the right thing to do, but they're not
very common.

If you do actually need the value of the variable rounded, and not just
the display of the variable, then the expression you've already been
given does the job:

value = ROUND(100.0*x)/100.0
Re: How to plot multiple charts and ho to round float to specific precision? [message #44972 is a reply to message #44858] Thu, 28 July 2005 06:23 Go to previous messageGo to next message
liko2@o2.pl is currently offline  liko2@o2.pl
Messages: 15
Registered: July 2005
Junior Member
I meant : after coma not zero.
Re: How to plot multiple charts and ho to round float to specific precision? [message #44973 is a reply to message #44858] Thu, 28 July 2005 05:24 Go to previous messageGo to next message
liko2@o2.pl is currently offline  liko2@o2.pl
Messages: 15
Registered: July 2005
Junior Member
No, it has to be a value of variable, later used for a part of title of
a chart. So it has to be exact value with only 2 digits after zero.
Re: How to plot multiple charts and ho to round float to specific precision? [message #44974 is a reply to message #44858] Thu, 28 July 2005 05:14 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
liko2@o2.pl wrote:
> No, this does only the rounding and output has still 4 digits after
> coma...I need to have only two digits after coma (eg. 23.46 not 23.4600)
>

It sounds like you don't want to *round* the number, but you want to
*print* it with a certain precision. Check the IDL help for "format
codes" and the FORMAT keyword to the STRING function and PRINT procedure.

IDL> print, 23.46, format='(f0.2)'
23.46

The "f" format code is for outputting floating point numbers. The "2"
means two digits after the decimal point. The "0" means "make the output
string just as long so that it fits".

Good luck,
Benjamin
Re: How to plot multiple charts and ho to round float to specific precision? [message #45044 is a reply to message #44960] Wed, 03 August 2005 01:19 Go to previous message
liko2@o2.pl is currently offline  liko2@o2.pl
Messages: 15
Registered: July 2005
Junior Member
Ok it does the thing - THX
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: CALL_EXTERNAL and C++ code
Next Topic: Re: Multilayered plots

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

Current Time: Wed Oct 08 15:12:07 PDT 2025

Total time taken to generate the page: 0.00520 seconds