# [ncl-talk] Using a loop to find values greater than 0 (calculate PDD)

Dennis Shea shea at ucar.edu
Mon Aug 4 10:11:24 MDT 2014

```The variable, tasC, is an *array *

tasC = tasL - 273.15 ; Convert K to C
printVarSummary(tasC)

You can not use an array as a loop variable ... in any language.

do tasC = 0,364

could be, say,

do day = 0,364

See:
https://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Loops

Specifically:

do *loop_identifier* = *scalar_start_expr* ,

*end_expr*

*T*he "scalar_start_expr , end_expr" are scalar.

===

r2i1p1_18700101-19001231.nc","r")
tasL  = a->tas(0:364,:,:)

TIME = cd_calendar(tasL&time,0)   ; TIME(ntim,6)
print(TIME)

tasC = tasL - 273.15 ; Convert K to C
tasC = where(tasC.gt.0.0, tasc, 0.0)
pdd  = dim_sum_n_Wrap(tasC, 0)       ; (lat,lon)
pdd at long_name = "degree days for year="+toint(TIME(0,0))
pdd at units = "degC"

On Mon, Aug 4, 2014 at 9:16 AM, Lauren Jean Vargo <lvargo at unm.edu> wrote:

> Hello,
>
> I’m having trouble doing a calculation with NCL, ultimately I am trying to
> calculate the Positive degree-day (PDD) sum. I’ve read in daily temperature
> data (which is 3D [time,lat,lon]). What I am trying to do is calculate the
> sum of the temperatures that are greater than 0C for 1 year.
>
> The way I was trying to do this was with a loop, and to first set any
> temperature less than or equal to zero, just to zero. Next I want to sum
> all the temperatures over 365 days at each lat & lon point. If there is an
> easier way to do this using NCL functions, that would be great.
>
> The error message that I am getting is that the “loop must be scalar".
> However, I’m not sure how to specify that I want the temperature value to
> be analyzed when tasC is (time,lat,lon).
>
> I’ve uploaded the file "tas_day_CCSM4_lgm_r2i1p1_18700101-19001231.nc” to
> the ftp account.
>
> I’m running ncl version 6.1.2, and the system is Darwin Kernel Version
> 13.3.0
>
>
> Here is the script:
>
>
> begin
>
> ; Read in near surface air temperature (Ta)
>
>                 a =
>                 tasL = a->tas(0:364,:,:)
>                 tasC = tasL - 273.15 ; Convert K to C
>                 print (tasC)
>                 printVarSummary (tasC)
>
>                 do tasC = 0,364
>                         if (tasC .le. 0)
>                                 H = 0
>                         end if
>                 end do
>
>                 PDD_sum = dim_cumsum_n_Wrap(tasC)
>
> end
>
>
> Any help would be greatly appreciated.
>
> Thanks,
>
> Lauren Vargo
> M.S. Candidate
> The University of New Mexico
> _______________________________________________
> ncl-talk mailing list
> 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/20140804/571eb834/attachment.html
```