//scs rainfall object
// 2/9/2009

function SCS(distribution_type)
{
	//scs rainfall object

	this.depth=depth;
	this.factor=factor;
	this.hyetograph=hyetograph;
	//create depth array multiplication factor

	function factor(t_hour)
	{
		//returns the multiplication factor to obtain scs rainfall depth for time=t_hour
		switch (distribution_type.toUpperCase())
		{
		case "I":
		{var K= new Array(0,8,17,26,35,45,55,65,76,87,99,112,125,140,156,174,194,219,254,303,515,583,624,654,682,706,728,748,766,783,799,815,830,844,857,870,882,893,905,916,926,936,946,956,965,974,983,992,1000);}
		  break;
		case"IA":
		{var K=new Array(0, 10, 22, 36, 51, 67, 83, 99, 116, 135, 156, 179, 204, 233, 268, 310, 425, 480, 520, 550, 577, 601, 623, 644, 664, 683, 701, 719, 736, 753, 769, 785, 800, 815, 830, 844, 858, 871, 884, 896, 908, 936, 946, 956, 965, 974, 983, 992, 1000);}
		  break;
		case "II":
		{var K=new Array( 0, 5, 11, 17, 23, 29, 35, 41, 48, 56, 64, 72, 80, 90, 100, 110, 120, 133, 147, 163, 181, 203, 236, 283, 663, 735, 776, 804, 825, 842, 856, 869, 881, 893, 903, 913, 922, 930, 938, 946, 953, 959, 965, 971, 977, 983, 989, 995, 1000);}
		  break;
		default:
		{var K=new Array(0, 5, 10, 15, 20, 26, 32, 37, 43, 50, 57, 65, 72, 81, 89, 102, 115, 130, 148, 167, 189, 216, 250, 298, 600, 702, 751, 765, 811, 830, 848, 867, 886, 895, 904, 913, 922, 930, 939, 948, 957, 962, 968, 973, 979, 984, 989, 995, 1000);}
		}

		return K.interpolate(t_hour*2)/1000.0;
	}//end factor
	
	function depth(t_hour,totalDepth)
	{	//cumulative rainfall depth upto t_hour
		return factor(t_hour,distribution_type)*totalDepth;
	}
	
	function hyetograph(totalDepth,dt)
	{	//returns array of intensities in inch per hour
              //totalDepth= depth for 24 hours
                //dt=interval in minutes
		var A=new Array();
		var steps=24*60/dt;
		for(var k=0;k<steps;k++)
			{		var a=depth((k+1)*dt/60,totalDepth);
					var b=depth((k)*dt/60,totalDepth);
					A[k]=(a-b)/dt*60;
					//console.log(k+' : '+a.toFixed(3)+' : '+b.toFixed(3)+' : '+A[k].toFixed(3));
					//A[k]=(depth((k+1)*dt,totalDepth)-depth((k)*dt,totalDepth))/dt*60;
			}
			return A;
	}




}//end of SCS