/*harvest.aml
/*this aml calculates snow accumulation,snowmelt,and WAR for an uncut 
/*and clearcut watershed
/*created by Beth Evans, March 8th, 1999
/*-------------------------------------------------------------------
/*calls Grids:  digital elevation grid in meters(dem_m),
/*              forest canopy grid in fractional cover (canopy_f),
/*              grid of stream network with streamcells = 1 (streamgrid)
/*Returns grids:swe(cm), snowmelt(cm),WAR(cm), war_acc(cm),
/*              percentdif(percent), reachdif(percent)
/*---------------------------------------------------------------------------------
/* calculate snowfall(cm)for basin
/* set variable for snow accumulation (average or unusual)
&sv snow = [response 'enter A for average snow accumulation or U for unusual~
 snow accumulation']
/*
/* set variables d1 and d2 and SEE
&sv d1 = -0.357
&sv d2 = 0.02029
&sv see = 7.332
/*
/*calculate snowfall grid
&if [exists snowfall -grid] &then kill snowfall
&if %snow% = A &then snowfall = %d1% + (%d2% * dem_m)
   &else snowfall = %d1% + (%d2% * dem_m) + %see%  
/*
/* calculate R coefficients for uncut and clearcut basins
&if [exists r_uncut -grid] &then kill r_uncut
&if [exists r_cut -grid] &then kill r_cut
r_uncut = 1 + 2 * ((1500 - dem_m) div 1500) * (1 - canopy_f)
r_cut = 1 + 2 * ((1500 - dem_m) div 1500) 
/*
/* calculate swe in cm for the uncut and clearcut basins
&if [exists swe%snow%uncut -grid] &then kill swe%snow%uncut 
&if [exists swe%snow%cut -grid] &then kill swe%snow%cut 
swe%snow%uncut = snowfall * r_uncut
swe%snow%cut = snowfall * r_cut
/*
/*set variable for average storm or unusual storm
&sv storm = [response 'enter A for average storm or U for unusual storm']
/*
/*create temperature grid degrees C
&if [exists T -grid] &then kill T
&if storm = A &then T = 8.1 - (0.006 * dem_m)
   &else T = 8.1 - (0.006 * dem_m) + 2
/*
/*create a windspeed grid (m/s)
&if storm = A &then &sv Uc = 5
   &else &sv Uc = 8 
&if [exists U_uncut -grid] &then kill U_uncut
U_uncut = %Uc% * (1 - (0.8 * canopy_f))
/*
/*set variable for storm recurrence interval
&sv RI = [response 'enter 24-hr storm recurrence interval in years']
/*
/*set precipitation variable for 24 hour storm (cm)
&sv P = [response 'enter precipitation for the 24-hr storm in cm']
/*
/*calculate snowmelt
&if [exists melt%storm%%ri%uncut -grid] &then kill melt%storm%%ri%uncut 
&if [exists melt%storm%%ri%cut -grid] &then kill melt%storm%%ri%cut 
melt%storm%%ri%uncut = T * (0.133 + (0.086 * U_uncut) + (0.0126 * %P%)) + 0.23
melt%storm%%ri%cut = T * (0.133 + (0.086 * %Uc%) + (0.0126 * %P%)) + 0.23
/*
/*calculate water available for runoff (WAR)
&if [exists war%snow%%storm%%ri%uncut -grid] &then kill war%snow%%storm%%ri%uncut 
&if [exists war%snow%%storm%%ri%cut -grid] &then kill war%snow%%storm%%ri%cut 
war%snow%%storm%%ri%uncut = con(melt%storm%%ri%uncut > swe%snow%uncut,~
 swe%snow%uncut,melt%storm%%ri%uncut) + %P%
war%snow%%storm%%ri%cut = con(melt%storm%%ri%cut > swe%snow%cut,swe%snow%cut,~
 melt%storm%%ri%cut) + %P%
/*
/*fill dem and create flowdirection grid
&if [exists filldem -grid] &then kill filldem 
&if [exists flowdir -grid] &then kill flowdir 
fill dem_m filldem # # flowdir
/*
/*calculate percent difference in WAR accumulation between uncut and cut basins
&if [exists acc%snow%%storm%%ri%uncut -grid] &then kill acc%snow%%storm%%ri%uncut 
&if [exists acc%snow%%storm%%ri%cut -grid] &then kill acc%snow%%storm%%ri%cut 
acc%snow%%storm%%ri%uncut = flowaccumulation(flowdir,war%snow%%storm%%ri%uncut)
acc%snow%%storm%%ri%cut = flowaccumulation(flowdir,war%snow%%storm%%ri%cut)
&if [exists percentdif%snow%%storm%%ri% -grid] &then kill percentdif%snow%%storm%%ri% 
percentdif%snow%%storm%%ri% = (acc%snow%%storm%%ri%cut - acc%snow%%storm%%ri%uncut)~
 div acc%snow%%storm%%ri%uncut * 100
/*
/*calculate percent difference in WAR accumulation for each stream reach
&if [exists reachdif%snow%%storm%%ri% -grid] &then kill reachdif%snow%%storm%%ri% 
reachdif%snow%%storm%%ri% = con(streamgrid == 1,percentdif%snow%%storm%%ri%)
&return