<span style="color: rgb(0, 0, 0); font-family: Tahoma,sans-serif; font-size:
13px;"><br>Diane:<br>
<br>
I corrected my Fortran code according to your 2nd suggestion, and the
values from fortran and grads matched (with small errors, but not
significant).<br>
<br>
Thanks,<br>
Sandra<br>
<div id="__assinatura__"> </div><blockquote id="prevContent"
style="border-left: 2px solid rgb(0, 0, 0); color: rgb(0, 0, 0); font-family:
arial,verdana,sans-serif; font-size: 10pt; padding-right: 0px; padding-left:
5px; margin-left: 5px; margin-right: 0px;"><div style="color: rgb(0, 0, 0);
font-family: arial; font-style: normal; font-variant: normal; font-weight:
normal; font-size: 10pt; line-height: normal; font-size-adjust: none;
font-stretch: normal;">----- Original Message ----- </div><div style="color:
rgb(0, 0, 0); background-color: rgb(228, 228, 228);"><b>De:</b> Diane Stokes
&lt;<span class="spanLink" style="cursor: pointer;"
onclick="a6H({c2o:a3w.g52(), b7y:event, e0e: 'Diane.Stokes@NOAA.GOV',
label:'Diane Stokes', g6C:1}); c44(event);">Diane.Stokes@NOAA.GOV</span>&gt;
</div><div style="color: rgb(0, 0, 0); font-family: arial; font-style: normal;
font-variant: normal; font-weight: normal; font-size: 10pt; line-height:
normal; font-size-adjust: none; font-stretch: normal;"><b>Para:</b> &lt;<span
class="spanLink" style="cursor: pointer;" onclick="a6H({c2o:a3w.g52(),
b7y:event, e0e: 'GRADSUSR@LIST.CINECA.IT', label:'', g6C:1});
c44(event);">GRADSUSR@LIST.CINECA.IT</span>&gt;</div><div style="color: rgb(0,
0, 0); font-family: arial; font-style: normal; font-variant: normal;
font-weight: normal; font-size: 10pt; line-height: normal; font-size-adjust:
none; font-stretch: normal;"><b>Data:</b> 23/02/2007 15:23</div><div
style="color: rgb(0, 0, 0); font-family: arial; font-style: normal;
font-variant: normal; font-weight: normal; font-size: 10pt; line-height:
normal; font-size-adjust: none; font-stretch: normal;"><b>Assunto:</b> Re:
problems with aave</div>I see two (maybe three) contributing factors to the
difference:<br>
<br>
First, the result from aave is latitude weighted.  From the documentation:<br>
<br>
"The aave function assumes that the world coordinates are longitude in<br>
the X dimension and latitude in the Y dimension, and does weighting in<br>
the latitude dimension by the difference between the sines of the<br>
latitude at the northern and southern edges of the grid box. For areal<br>
averaging without latitude weighting, use the amean function."<br>
<br>
The impact of using aave vs amean depends on the latitude range of your<br>
region.<br>
<br>
<br>
Second, in your fortran code, the denominator is too small when you<br>
divide mh(i) by the number of gridsquares.  You have:<br>
   mh(i)=mh(i)/((35-26)*(50-43))<br>
Try:<br>
   mh(i)=mh(i)/((35-26+1)*(50-43+1))<br>
<br>
<br>
A third (possible) factor is that you have missing value(s) that would<br>
get excluded from the aave (or amean) calculation but are not excluded<br>
in the code.  The impact from that would depend on the value you use for<br>
"missing".<br>
<br>
<br>
    Diane<br>
<br>
<br>
sansaad wrote:<br>
&gt; Hi everybody<br>
&gt;<br>
&gt; I'd done some calculations using both GRADS and Fortran, and I realised
<br>
&gt; that the spatial average using GRADS (aave) differs by a ratio of<br>
&gt; approximately 0.787 from the spatial average using Fortran. By this I<br>
&gt; mean that if I multiply the Fortran's values by 0.787, they ALWAYS match
<br>
&gt; with the GRADS' values (with small errors).<br>
&gt;<br>
&gt; Can anyone explain the reason for this "magic number" (0.787)?<br>
&gt;<br>
&gt; A part of the program using GRADS and Fortran respectively are given<br>
&gt; bellow.<br>
&gt;<br>
&gt; I would appreciate any kind of commentaries.<br>
&gt;<br>
&gt; Sandra Saad<br>
&gt;<br>
&gt;<br>
&gt; ### Spatial Average using GRADS ########<br>
&gt;<br>
&gt; set t 1 last<br>
&gt; d aave(h,x=26,x=35,y=43,y=50)<br>
&gt;<br>
&gt;<br>
&gt; ###  Spatial Average using Fortran (90) ########<br>
&gt;<br>
&gt;  do i=1,it<br>
&gt;   do ny=43,50<br>
&gt;    do nx=26,35<br>
&gt;     mh(i)=mh(i)+h(i,nx,ny)<br>
&gt;    enddo<br>
&gt;   enddo<br>
&gt;  mh(i)=mh(i)/((35-26)*(50-43))<br>
&gt;  enddo<br>
&gt;<br>
&gt;  do i=1,it<br>
&gt;   write(3,*)i,mh(i)<br>
&gt;  enddo<br>
&gt;<br>
</blockquote>
</span>