[ncl-talk] problem with function (sum)

Mary Haley haley at ucar.edu
Sat Apr 16 08:13:51 MDT 2016


Xia,

Thanks for providing a script.

You are running out of precision to do a calculation of this size.

In your script you are defining some variables to be float, but they should
be double. Here are the changes I made to get your script to work:

32c32
<      dzTB=new((/mdims1(1),mdims1(2),mdims1(3)/),"float")
---
>      dzTB=new((/mdims1(1),mdims1(2),mdims1(3)/),"double")
40,41c40,41
<         TB = new((/tsize/),float)
<         TB2 = new((/tsize/),float)
---
>         TB = new((/tsize/),double)
>         TB2 = new((/tsize/),double)

​Once you implement this fix, you should get numbers like this for TB / TB2:

Variable: TB (subsection)
Type: double
. . .
(0) 13485314827.10813
(1) 13483945432.40879
(2) 13482898073.04566


Variable: TB2 (subsection)
Type: double
. . .
(0) 13485314827.13124
(1) 13483945432.41978
(2) 13482898073.05505​

​I made some other changes to your script to clean it up a little.  It is
not necessary to have that "if" statement inside your code.​ You can create
TB / TB2 outside the loop and get rid of the "if" statement entirely.

See the attached modified script.

--Mary

On Fri, Apr 15, 2016 at 4:19 PM, Xia Chu <xchu1 at uwyo.edu> wrote:

> Dear helpers,
>
> I'm trying to do summation of a 3D array using function (sum). When the
> data is 60x512x512 in dimension it works fine. However, with a larger
> data set of 60x1536x1536, the summation came to 4.29497e+09 which is
> definitely wrong. I had to use dim_sum_n to sum two dimension first and
> then another sum. I also find summation value varies if I dim_sum_n
> different dimensions first. This problem only stands out with variable
> QVAPOR (not QCLOUD or other mixing ratios) which have values at every
> grids.
>
> The code is attached. I'm working on Yellowstone supercomputer. The
> script has my working directory. You should be able to run the script on
> Yellowstone. I'm using ncl/6.3.0.
>
> Would you recommend a good way to do summation? I'm trying to calculate
> total mass.
>
> I would appreciate any of your help! Thanks in advance.
>
> Best,
> Xia
>
> --
> Xia Chu
>
> PhD Candidate
> Graduate Research Assistant
> Department of Atmospheric Science
> University of Wyoming
> Dept. 3038, 1000 E. University Ave.
> Laramie, Wyoming 82071
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160416/22ecf051/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mass_mod.ncl
Type: application/octet-stream
Size: 1382 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160416/22ecf051/attachment.obj 


More information about the ncl-talk mailing list