<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
First, you say you know there are nicer ways, why aren't you using
one of them? This is a one-line operation in ncl using <tt>dim_avg_n_Wrap</tt>,
which also eliminates the loop, which is inherently slow in
interpreted languages like NCL.<br>
<br>
Second, using a fill value of zero is definitely the problem and
just a bad idea generally. Because you assign the zero as the
missing value and then initialize the array with zeros, when you try
to add a value to that, the result is still a missing value ( ? + a
= ? ). If you want to do it this way, you need to either use a
different missing value or initialize the sum to the first sst value
instead. Plus, if you want an average, you need to divide by the
number of times at the end.<br>
<br>
Also note that if your data actually *has* missing data, your method
will produce missing data at those locations, whereas using the
built-in function will ignore the missing data and calculate the
average based on times that exist.<br>
<br>
Third, you are overwriting the fill value is for the input data. It
is likely you don't even need to set the fill value, but if you do
you should make sure you are setting it to the proper value for your
dataset, which is unlikely to be zero, as zero is a terrible choice
for anomaly data where 0 is a valid (even common) value.<br>
<br>
- Walter<br>
<br>
<div class="moz-cite-prefix">On 2015-09-30 19:34, Sebastian
Otarola-Bustos wrote:<br>
</div>
<blockquote
cite="mid:CAO9pyikN7Yt=iQ9hyEaXaVdDvU6_TL_KfrvABEi+g9_J+f=3uQ@mail.gmail.com"
type="cite">
<div dir="ltr">Hi everybody, I'm working with NOA high resolution
daily sea surface temperature anomalies. I have 3D variable
sst(days,lat,lon) and want to compute average for the week, so I
created sst_avg(lat,lon) float 2D array full with zeros, to save
the sum of all days in this variable( very simple). But the
problem is that this sum is not working so sst_avg is full of
zeros after the operation.
<div><br>
</div>
<div>The main features of the code arre below:<br>
<br>
<div><b><font face="garamond, serif">sst = a->anom</font></b></div>
<div><b><font face="garamond, serif">dims = dimsizes(sst)</font></b></div>
<div><b><font face="garamond, serif">times = dims(0)</font></b></div>
<div><b><font face="garamond, serif">row = dims(1)</font></b></div>
<div><b><font face="garamond, serif">col = dims(2)<br>
<br>
</font></b></div>
<div><b><font face="garamond, serif">sst@_FillValue = 0.</font></b></div>
<div><b><font color="#ff9900" face="garamond, serif">sst_avg =
new((/row,col/),"float",0.)</font></b></div>
<div><b><font face="garamond, serif">sst_avg@_FillValue = 0.</font></b></div>
<div><b><font face="garamond, serif">copy_VarCoords(sst(0,:,:),sst_avg)</font></b></div>
<div><b><font face="garamond, serif"> printVarSummary(sst) <br>
do it =0,times-1</font></b></div>
<div><b><font face="garamond, serif"> <font
color="#ff9900">sst_avg = sst_avg + sst(it,:,:)</font></font></b></div>
<div><b><font face="garamond, serif">
print(sst_avg)</font></b></div>
<div><b><font face="garamond, serif"> end do</font></b></div>
<div><b><font face="garamond, serif">printVarSummary(sst_avg)<br>
</font></b><br>
sst.PNG, and sst_avg.PNG show the information of sst and
sst_avg after the iteration.<br>
<br>
I thought that has something to do with @FillValue, but I
changed this and the only thing I got was very huge and
nonsense numbers instead of sst_avg full with zeros.<br>
<br>
P.S: I know there are nicer ways of computing average, but
my doubt is mainly about the sum that is not working. Thank
you very much in advance and any help would be really
appreciated.<br>
<br>
All the best,<br>
Sebastián.</div>
<div><br>
</div>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
ncl-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
</pre>
</blockquote>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
        <tr>
                <td style='border:none;padding:0px 15px 0px 8px'>
                        <a href="https://www.avast.com/antivirus">
                                <img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
                        </a>
                </td>
                <td>
                        <p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
                                This email has been checked for viruses by Avast antivirus software.
                                <br><a href="https://www.avast.com/antivirus">www.avast.com</a>
                        </p>
                </td>
        </tr>
</table>
<br />
</body>
</html>