[ncl-talk] how can I write large float value with e scientific notation?

Beáta Szabó-Takács szabo.b at czechglobe.cz
Tue Sep 12 23:57:16 MDT 2017


Dear Adam and Michael,

Thank you very much for your help! It works.

Kind regards,
Beáta

From: Adam Phillips [mailto:asphilli at ucar.edu]
Sent: Tuesday, September 12, 2017 5:25 PM
To: Beáta Szabó-Takács <szabo.b at czechglobe.cz>
Cc: Michael Langguth <mlangguth at uni-bonn.de>; ncl-talk at ucar.edu
Subject: Re: [ncl-talk] how can I write large float value with e scientific notation?

Hi Beáta,

I would suggest copying the taylor_metrics_table.ncl function to the top of your script, and rename it. Then, you can modify it as you like and call it within your main script.
https://www.ncl.ucar.edu/Applications/Scripts/taylor_metrics_table.ncl

The line that is causing your issue is this line:
gsn_text_ndc(wks,sprintf("%4.3f",values(icase,iseas,im)),ixtbox,iytbox, mv_tRes)

Following Michael's suggestion, you could put in an if statement like this:
if (values(icase,iseas,im).gt.100000) then
   gsn_text_ndc(wks,sprintf("%4.2g",values(icase,iseas,im)),ixtbox,iytbox, mv_tRes)
else
   gsn_text_ndc(wks,sprintf("%4.3f",values(icase,iseas,im)),ixtbox,iytbox, mv_tRes)
end if

Hope that helps!
Adam

On Tue, Sep 12, 2017 at 7:17 AM, Beáta Szabó-Takács <szabo.b at czechglobe.cz<mailto:szabo.b at czechglobe.cz>> wrote:
Dear Michael,
Thank you for your response. Unfortunately it does not work because the values can be only numeric in taylor_metric_table.ncl.
Best regards,
Beáta

-----Original Message-----
From: Michael Langguth [mailto:mlangguth at uni-bonn.de<mailto:mlangguth at uni-bonn.de>]
Sent: Tuesday, September 12, 2017 2:32 PM
To: Beáta Szabó-Takács <szabo.b at czechglobe.cz<mailto:szabo.b at czechglobe.cz>>; ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] how can I write large float value with e scientific notation?

Dear Beáta,

I suppose, the sprintf-function can help you here. It's a function to convert floats (and doubles) to formatted strings.
For example, an appropriate format for your bias-values may be

sprintf("%10.5g",bias)

where the exponential notation is used as long as the precision being defined by the number 5.

For further examples, you can also consult the attached
link:
https://www.ncl.ucar.edu/Document/Functions/Built-in/sprintf.shtml

Best regards
Michael

  On Tue, 12 Sep 2017 11:18:59 +0000
  Beáta Szabó-Takács <szabo.b at czechglobe.cz<mailto:szabo.b at czechglobe.cz>> wrote:
> Dear NCL Users,
> I created a table about precipitation bias values in JJA and DJF with
>taylor_metric_table.ncl. I changed the bias calculation to
> bias    = tmean-rmean in taylor_stats.ncl. I got a very
>large bias value in HIRHAM model in JJA and this value covers the bias
>value in DJF column on the table. I attached the table. The values are
>in float form. Could someone let me know how I can write the large
>float number with scientific notation? I mean if the value is e.g
>larger than 100000 it will be written 1e5.
> Thank you for your help in advance!
> Beáta

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



--
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/<http://www.cgd.ucar.edu/staff/asphilli/>   303-497-1726<tel:(303)%20497-1726>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170913/f2266a14/attachment.html>


More information about the ncl-talk mailing list