<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi Alan,
<div class=""><br class="">
</div>
<div class="">Thanks for this, both for the suggestions and the effort to debug the code.</div>
<div class=""><br class="">
</div>
<div class="">The first element of the dp unfortunately is not playing any part to it, as I’ve tried it with either dp(0) =-dp(1) or with just setting it as zero. </div>
<div class=""><br class="">
</div>
<div class="">So unfortunately I’m back to square 1.</div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">
<div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Andreas</div>
<div class=""><br class="">
</div>
<div class=""></div>
</div>
</div>
</div>
</div>
</div>
</div>
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 27 Mar 2018, at 04:56, Alan Brammer <<a href="mailto:abrammer@albany.edu" class="">abrammer@albany.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div class="gmail_default" style="font-family:verdana,sans-serif"><br class="">
</div>
<div class="gmail_default" style="font-family:verdana,sans-serif">I think the problem may be here:</div>
<div class="gmail_default" style="font-family:verdana,sans-serif">
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
if (k .eq. 0) then<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
dp(k) = lev(k)*100</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
So in one direction dp(0) = 0.1 *100</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
in the other direction dp(0) = 1000*100</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
That seems like it would introduce some large differences depending on the direction of the array. </div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
There is this function to calculate pressure differences <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/dpres_plevel.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/Built-in/dpres_plevel.shtml</a></div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
Also, some minor suggestions:</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
1.</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
I think this can be broken out of a loop and just computed as an array. Should be marginally faster in NCL. </div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
COSLAT(j) = cos(lat(j)*d2rad)<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
COSLAT = cos(lat*d2rad)<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
2. </div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
in Method 1. </div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
The j, loop can be removed and just compute on all lats at once. Nested do loops become slow rather quickly in NCL, better to vectorise as mush as possible.</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
do k=0...</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
....</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
psistar(k,:) = 2*pi*r*COSLAT*(VSTAR(k,:)*<wbr class="">dp(k))/g<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
....</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
end do</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
<div style="font-family: arial, sans-serif; font-size: 12.800000190734863px;" class="">
<br class="">
</div>
</div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Mon, Mar 26, 2018 at 11:19 AM, Andreas Chrysanthou <span dir="ltr" class="">
<<a href="mailto:eeac@leeds.ac.uk" target="_blank" class="">eeac@leeds.ac.uk</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">
<div style="word-wrap:break-word" class="">Hi NCL users,
<div class=""><br class="">
</div>
<div class="">I came up into something really weird unless I’m ignoring something really big, which is not likely. </div>
<div class=""><br class="">
</div>
<div class="">I’m trying to calculate the mass streamfunction (psistar) from the meridional velocity and when I’m integrating downwards (reversing the v wind array) from Top of the Atmosphere (TOA - 0.1hPa) to Bottom (1000hPa) the calculation yields some very
realistic values and the proper structure. (Magnitude 10^9 Kg s-1). </div>
<div class=""><br class="">
</div>
<div class="">If I try to do that the other way round (from bottom-TOA) I’m getting a difference of 10^3 in the magnitude and not a very smooth structure and this is really counter intuitive. Any ideas If I’m doing something wrong?</div>
<div class=""><br class="">
</div>
<div class="">Attached is a snip of my script with the relevant part. Also two plots of both version to compare the differences.</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">; Constants </div>
<div class="">pi = 4.*atan(1.)</div>
<div class="">r = 6371*10^3 ; Earth Radius</div>
<div class="">g = 9.81 ; m/s2 Gravity</div>
<div class="">d2rad = 0.017453 ; degrees to radians</div>
<div class=""><br class="">
</div>
<div class="">varname = "vstar"</div>
<div class=""><br class="">
</div>
<div class="">vstar = ff1->$varname$(0:599,:,:,0) ; normal array pressure levels (1000->01.hPa)</div>
<div class="">;vstar = vstar(:,::-1,:) ; uncomment if integrating from top -> bottom</div>
<div class=""><br class="">
</div>
<div class="">VSTAR = dim_avg_n_Wrap(vstar, 0) ; just a timemean</div>
<div class="">printVarSummary(VSTAR)</div>
<div class="">printMinMax(VSTAR,1)</div>
<div class=""><br class="">
</div>
<div class="">lat = VSTAR&lat</div>
<div class="">lev = VSTAR&lev</div>
<div class=""><br class="">
</div>
<div class="">nlev = dimsizes(lev)</div>
<div class="">nlat = dimsizes(lat)</div>
<div class=""><br class="">
</div>
<div class="">dp = new(nlev,typeof(lev))</div>
<div class="">do k = 0,nlev-1</div>
<div class=""> if (k .eq. 0) then</div>
<div class=""> dp(k) = lev(k)*100</div>
<div class=""> else</div>
<div class=""> dp(k) = abs((lev(k)-lev(k-1))*100)</div>
<div class=""> end if</div>
<div class="">end do</div>
<div class=""><br class="">
</div>
<div class="">COSLAT = new(nlat,typeof(lat))</div>
<div class="">do j = 0, nlat-1</div>
<div class=""> COSLAT(j) = cos(lat(j)*d2rad)</div>
<div class="">end do</div>
<div class="">print(COSLAT)</div>
<div class=""><br class="">
</div>
<div class="">psistar = new((/nlev,nlat/),"double") ; allocate space</div>
<div class="">psistar!0 = "lev"</div>
<div class="">psistar!1 = "lat"</div>
<div class="">psistar&lev = lev</div>
<div class="">psistar&lat = lat</div>
<div class=""><br class="">
</div>
<div class="">;*****************************<wbr class="">******************************<wbr class="">******************************<wbr class="">***************</div>
<div class="">; NOTE these two methods yield identical results, correct if lev axis is reversed. When not, integrating</div>
<div class="">; bottom to the top yields unrealistic results with both formulations</div>
<div class=""><br class="">
</div>
<div class="">; #1 Method</div>
<div class="">do j = 0, nlat-1</div>
<div class=""> do k = 1, nlev-1 </div>
<div class=""> psistar(0,:) = 0</div>
<div class=""> if (k .eq. 0) then</div>
<div class=""> psistar(k,j) = 2*pi*r*COSLAT(j)*(VSTAR(k,j)*<wbr class="">dp(k))/g</div>
<div class=""> else if (k .gt. 0)</div>
<div class=""> psistar(k,j) = psistar(k-1,j) + (2*pi*r*COSLAT(j)*(VSTAR(k,j)*<wbr class="">dp(k)))/g</div>
<div class=""> end if</div>
<div class=""> end if</div>
<div class="">end do</div>
<div class="">end do</div>
<div class=""><br class="">
</div>
<div class="">; #2 Method</div>
<div class="">;do j = 0, nlat-1</div>
<div class="">; do k = 0 , nlev-1</div>
<div class="">; ;psistar(0,j) = 0</div>
<div class="">; psistar(k,j) = 2*pi*r*COSLAT(j)*dim_sum(<wbr class="">VSTAR(0:k,j)*dp(0:k))/g</div>
<div class="">; psistar(0,j) = 0</div>
<div class="">; ;psistar(nlev-1,j) = 0 </div>
<div class="">; end do</div>
<div class="">;end do</div>
<div class=""><br class="">
</div>
<div class="">;*****************************<wbr class="">******************************<wbr class="">******************************<wbr class="">******************</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""></div>
</div>
</div>
<div style="word-wrap:break-word" class="">
<div class="">
<div class=""></div>
</div>
</div>
<div style="word-wrap:break-word" class="">
<div class="">
<div class=""></div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">Andreas</div>
<div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class="">
<div class=""><br class="">
</div>
<div class=""></div>
</div>
</div>
</div>
</div>
</div>
</div>
<br class="">
</div>
</div>
</div>
<br class="">
______________________________<wbr class="">_________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/<wbr class="">mailman/listinfo/ncl-talk</a><br class="">
<br class="">
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>