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

Lauren Jean Vargo lvargo at unm.edu
Mon Aug 4 09:16:12 MDT 2014


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: 

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"  
load “$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"  

begin

; Read in near surface air temperature (Ta) 	

		a = addfile("tas_day_CCSM4_lgm_r2i1p1_18700101-19001231.nc","r") 
		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


More information about the ncl-talk mailing list