function calcTexturalClass(psand,pverycoarse,pcoarse,pmedium,pfine,pveryfine,psilt,pclay)
 {
  var texture = "unknown";
  var ps = Number(psand);
  var pvc = Number(pverycoarse);
  var pc = Number(pcoarse);
  var pm = Number(pmedium);
  var pf = Number(pfine);
  var pvf = Number(pveryfine);
  var psi = Number(psilt);
  var pcl = Number(pclay);
  var calcSubClass = true;
  if ((pvc == 0) && (pc == 0) && (pm == 0) && (pf == 0) && (pvf == 0))
    calcSubClass = false;
  if((psi >= 80) && (pcl < 12))
    return "Silt (Si)";
   else
     if((psi >= 50) && (pcl < 27))
	   return "Silt Loam (SiL)";
  if((ps <= 20) && (pcl >= 27) && (pcl < 40))
    return "Silty Clay Loam (SiCL)";
  if((psi >= 40) && (pcl >= 40))
    return "Silty Clay (SiC)";
  if((ps >= 45) && (pcl >= 35))
    return "Sandy Clay (SC)";
  if((ps >= 20) && (ps < 45) && (pcl >= 27) && (pcl < 40))
    return "Clay Loam (CL)";
  if((pcl >= 40) && (ps < 45) && (psi < 40))
    return "Clay (C)";
  if((pcl >= 20) && (pcl < 35) && (psi <= 28) && (ps >= 45))
    return "Sandy Clay Loam (SCL)";
  if((pcl >= 7) && (pcl < 27) && (psi > 28) && (psi < 50) && (ps < 52))
    return "Loam (L)";
  if((ps > 85) && (psi + 1.5 * pcl < 15))
    texture = "Sand (S)";
   else
     if((ps > 70) && (psi + 2 * pcl < 30))
       texture = "Loamy Sand (LS)";
  if((ps >= 85) && (psi + 2 * pcl >= 15))
    texture ="Loamy Sand (LS)";
  if((pcl <= 20) && (psi + 2 * pcl >= 30) && (ps >= 52))
    texture = "Sandy Loam (SL)";
  if((pcl < 7) && (psi < 50) && (ps > 43) && (ps <= 52))
    texture = "Sandy Loam (SL)";
  if(texture == "Sand (S)")
    if (calcSubClass)
      {
       if((pvc + pc >= 25) && (pm < 50) && (pf < 50) && (pvf < 50))
         return "coarse " + texture;
       if((pf >= 50) || ((pvc + pc + pm < 25) && (pvf < 50)))
         return "fine " + texture;
       if(pvf >= 50)
         return "very fine " + texture;
      }
     else return texture;
  if(texture == "Loamy Sand (LS)")
    if (calcSubClass)
      {
       if((pc + pvc >= 25) && (pm < 50) && (pf < 50) && (pvf < 50))
         return "loamy coarse " + texture;
       if((pvc + pc + pm >= 25) && (pvc + pc < 25) && ((pf < 50) || (pvf < 50)))
         return "loamy " + texture;
       if((pf >= 50) || ((pvc + pc + pm < 25) && (pvf < 50)))
         return "loamy fine " + texture;
       if(pvf >= 50)
         return "loamy very fine " + texture;
      }
     else return texture;
  if(texture == "Sandy Loam (SL)")
    if (calcSubClass)
      {
       if((pc + pvc >= 25) && (pm < 50) && (pf < 50) && (pvf < 50))
         return "coarse " + texture;
       if((pf >= 30) && (pvf < 30) || ((pvc + pc + pm >= 15) && (pvc + pc + pm <= 30)) || ((pf + pvf > 40) && (pf >= 0.5 * (pf + pvf)) && (pvc + pc + pm < 15)))
         return "fine " + texture;
       if((pvf >= 30) && (pvc + pc + pm < 15) || ((pf + pvf > 40) && (pvf >= 0.5 * (pf + pvf)) && (pvc + pc + pm < 15)))
         return "very fine " + texture;
      }
     else return texture;
  return texture;
}