function calcMasterValuesHK(){
//warning="no warning";

// these are the boundary values for the sweater.
p.buttonBandWidth.value = 0; // take out if I add button bands.

// readjust sleeve to makes sure it's at least 2 stitches wide for hand knit.

origMinSleeveWidth=eval(p.minSleeveWidth.value)
extraWidth=divide(2,p.mainStIn.value)
p.minSleeveWidth.value=Math.ceil(10*  add(extraWidth,p.minSleeveWidth.value) )/10;
p.sleeveWidth.value=Math.max(eval(p.minSleeveWidth.value),eval(p.sleeveWidth.value));
p.backNeckDepth.value=divide(sub(p.sleeveWidth.value,origMinSleeveWidth),2);


    // rib values--  change later.
    bodyRibLength=eval(p.bodyTrim.value);
    sleeveRibLength=eval(p.cuffTrim.value);
    buttonBandWidth=eval(p.buttonBandWidth.value); //may be positive or negative.
    widthTwoRows=divide(2,p.mainRowIn.value);    

    bodyLength=sub(p.totalLength.value,bodyRibLength);  bodyLengthPrint=Math.round(bodyLength*10)/10;
    sleeveLength=sub(p.sleeveLength.value,sleeveRibLength);  sleeveLengthPrint=Math.round(sleeveLength*10)/10
    
    cuffRibRows= Math.round(mult(sleeveRibLength,p.mainRowIn.value));
    bodyRibRows = Math.round(mult(bodyRibLength,p.mainRowIn.value));

    //alert(cuffRibRows + ":" + bodyRibRows); // these may be being calculated elsewhere; if so I need to eliminate those lines of code.
    
    //alert(p.sleeveLength.value + "- " + sleeveRibLength + " = " + sleeveLength  );


    frontArmholeDepth=sub(p.armHoleDepth.value,p.backNeckDepth.value);frontArmholeDepthPrint=Math.round(frontArmholeDepth*10)/10;
    //alert("calc armholeDepth=" + p.armHoleDepth.value + "-"+ p.backNeckDepth.value +" front"+ frontArmholeDepth)
    
// note: I have a hidden "back neck depth, which is what you get if you don't short row. The real one is shaped.)
    backNeckDepthPrint=Math.round(mult(p.realBackNeckDepth.value,10))/10;
    p.frontNeckDepth.value = Math.max(eval(p.backNeckDepth.value),eval(p.frontNeckDepth.value));

    frontNeckDepth=sub(p.frontNeckDepth.value,p.backNeckDepth.value); // subtract because top sleeve value affect the front neck.

    lengthOneRow=divide(1,p.mainRowIn.value);

    frontNeckWidth=neckWidth;  
    frontChestWidth=divide(p.chest.value,2) 
    backChestWidth=divide(p.chest.value,2)


    halfFrontChest=frontChestWidth/2; halfFrontChestPrint=Math.round(halfFrontChest*10)/10;
    halfBackChest=backChestWidth/2; halfBackChestPrint=Math.round(halfBackChest*10)/10;
    
     
    // calculate cast on for body.
    
    if(p.hemSnug.selectedIndex == 0){ ratioHem=1 } 
    else(ratioHem = 0.9);
    
    if(p.stitchMult.selectedIndex==0){		evenBody = 0;evenNeck = 1; multiple=2; }// neck odd, body even.
    else if(p.stitchMult.selectedIndex==1){	evenBody=1; evenNeck = 0; multiple=2; }   
	else{evenBody = 0;evenNeck = 1; multiple=2; }// make it odd.  Fix later.
    
     // later set this with a toggle. 
    bodyFront=Math.round( (mult(frontChestWidth,p.mainStIn.value)-evenBody)/multiple)*multiple+evenBody;
    bodyBack= Math.round( (mult(backChestWidth,p.mainStIn.value)-evenBody )/multiple )*multiple+evenBody; 
    bodyStitches=bodyFront+bodyBack;
  
    // rib is 2 x 2 rib, always. (Also works for 1 x 1).
    castOnFront=	Math.floor( ratioHem*mult(frontChestWidth,p.mainStIn.value)/2)*2;
    castOnBack= 	Math.floor( ratioHem*mult( backChestWidth,p.mainStIn.value)/2)*2; 
    castOnBody=castOnFront+castOnBack;
    castOnBodyP1=castOnBody+1;
    
    incFront=bodyFront-castOnFront;
    incBack=bodyBack-castOnBack;
    
    // body length to underarm.
   lengthToUnderarm= sub(bodyLength,p.armHoleDepth.value);  // neither adjusted for back neck.
   
   //alert("actual armhole = " + p.armHoleDepth.value  +" : body without trim" +bodyLength+" : to underarm" + lengthToUnderarm + ": armhole on front" + frontArmholeDepth + " : backNeck = "+ p.backNeckDepth.value);
  
   rowsToUnderArm=Math.round( mult(lengthToUnderarm,p.mainRowIn.value)/2)*2;
    
    // sleeve stuff
    likelyTanTheta= divide(2,p.mainRowIn.value) / divide(1,p.mainStIn.value);
    likeTheta=Math.atan(likelyTanTheta);
    //likeTheta=likeTheta*180/Math.PI
    cosTheta=Math.cos(likeTheta);
    //alert(cosTheta);
    
    sleeveLengthToUnderarm= sleeveLength- frontArmholeDepth-mult(cosTheta, p.backNeckDepth.value);
    sleeveLengthToUnderarmM1=sleeveLengthToUnderarm- lengthOneRow;
    //alert(sleeveLength + " : " +sleeveLengthToUnderarm + " : "+ frontArmholeDepth)
    
    if(p.cuffSnug.selectedIndex == 0){ ratioHem=1; } 
    else if(p.cuffSnug.selectedIndex == 0){ratioHem = 0.9;}
    else{ratioCuff=0.8;}

	bicepStitches= Math.round( (mult(p.sleeveWidth.value,p.mainStIn.value)-evenBody)/multiple)*multiple+evenBody;    
    cuffStitches= Math.round( (mult(p.cuffWidth.value,p.mainStIn.value)-evenBody)/multiple)*multiple+evenBody;
   
	//alert("  cuffStitches= "+cuffStitches + "  bicepStitches=" + bicepStitches);
   
        
	incSleeveStitches=2*Math.floor( (bicepStitches-cuffStitches)/2);
    halfIncSleeve= incSleeveStitches/2;  
	cuffStitches=bicepStitches-incSleeveStitches;
	
	//alert("  cuffStitches= "+cuffStitches + "  bicepStitches=" + bicepStitches);
	
	maxCastOnCuff=2*Math.floor(cuffStitches/2); // forced increase after cuff.
	castOnCuff=	Math.round( (ratioCuff*mult(p.cuffWidth.value,p.mainStIn.value))/2)*2; 
	castOnCuff=Math.min(castOnCuff, maxCastOnCuff);
	
    castOnCuffP1=castOnCuff+1;
    incCuff=cuffStitches-castOnCuff;

    
    rowsSleeve=Math.round( mult(sleeveLengthToUnderarm,p.mainRowIn.value)/2)*2;
    
    extraRows= Math.round( (rowsSleeve/(halfIncSleeve+1) )/6 -1)*2 +2;
	
	
    incRowsSleeve= rowsSleeve-extraRows;// padding to let HKers have some slop.
    
    fastIncSleeve= Math.floor( incRowsSleeve/(halfIncSleeve+1) )-1;
    slowIncSleeve= Math.ceil( incRowsSleeve/(halfIncSleeve+1) )-1;
    printIncRowsSleeve= incRowsSleeve-fastIncSleeve-1;
    
    
    slowRegions= incRowsSleeve%(halfIncSleeve+1)
    fastRegions= (halfIncSleeve+1)-slowRegions;
    
    fastTimes=fastRegions-1; fastRows=(fastIncSleeve+1)*(fastTimes+1)
    slowTimes=slowRegions;   slowRows=(slowIncSleeve+1)*slowTimes;
    
	//alert('extra = '+ extraRows + "  rowsSleeve = " + rowsSleeve + " incRowsSleeve  "+  incRowsSleeve);
    //alert('fastRegions = '+ fastRegions + "  slowRegions = " + slowRegions + " halfIncSleeve  "+  halfIncSleeve);
	
    stitchesAfterFast= bicepStitches-slowTimes*2;
   
    //unnderarm
    
    underArmCut=divide(p.chest.value,40);   
    halfUnderArmStitches=  Math.round(mult(underArmCut,p.mainRowIn.value)-0.5);
    halfUnderArmStitchesP1 = halfUnderArmStitches+1
    underArmStitches=halfUnderArmStitches+halfUnderArmStitchesP1;  // always odd.
    
    frontYoke=bodyFront-underArmStitches;
    firstFrontYoke=frontYoke+halfUnderArmStitches;
    backYoke=bodyBack-underArmStitches;
    
    sleeveYoke=bicepStitches-underArmStitches;
    firstSleeveYoke=sleeveYoke+halfUnderArmStitchesP1;
//  raglan shaping

    neckStitches=Math.round( (mult(frontNeckWidth,p.mainStIn.value)-evenNeck)/multiple)*multiple+evenNeck;
    frontNeckStitches=Math.ceil( (mult(frontNeckWidth,p.mainStIn.value)-evenNeck)/(2*multiple))*multiple+evenNeck ;
    
    edgeNeckStitches=(neckStitches-frontNeckStitches)/2;// needs to be odd.
	frontNeckStitches = neckStitches-2*edgeNeckStitches; 
	
    edgeNeckStitchesM1=edgeNeckStitches-1;     
    frontNeckShapeRows= edgeNeckStitches*2;  // virtually always because I add 2 st every 2 rows.
    begEngeNeckStitches=  edgeNeckStitches+edgeNeckStitches+1;// this needs to be odd because first pass doesn't have a neck decrease.

// these need to match. 
    frontNeckShapeStitches = frontNeckStitches+ 2*begEngeNeckStitches; // +2 so there are 3 left
    sleeveStitchesAtNeck = sleeveYoke - (backYoke-frontNeckShapeStitches);

    
    //alert(neckStitches +" : " + frontNeckStitches +" : edge" +edgeNeckStitches +" : rows =" +frontNeckShapeRows) 
    
    heightNeckEdge=divide(frontNeckShapeRows,p.mainRowIn.value);
    widthNeckEdge=divide(edgeNeckStitches,p.mainStIn.value);
    
    // add extra info to front neck edge.
    p.frontNeckDepth.value = Math.round(add(p.backNeckDepth.value, heightNeckEdge)*10)/10;
    //alert(frontNeckShapeRows + " rows = " + heightNeckEdge + " inches : width="+  widthNeckEdge); 
    placketStitches=0; /// needs to be defined.
    
    if(placket=="yes"){
	placketMax=sub(p.armHoleDepth.value, p.frontNeckDepth.value);
	//alert("in Master: placketMax " + placketMax +" =" +  p.armHoleDepth.value +" -"+  p.frontNeckDepth.value);
	
	placketDepth=Math.min(eval(p.placketDepth.value), placketMax-2*lengthOneRow)
	placketDepth=Math.max(0,placketDepth);
	p.placketDepth.value = Math.floor(placketDepth*10)/10;
	//alert("in Master: custom = " + custom +" placket=" +  placket +" depth= "+  placketDepth + " max= " +placketMax ); 
	belowPlacket = placketMax-placketDepth;
	
	placketWidth=eval(p.placketWidth.value);
	//alert(placketWidth);
	placketStitches=Math.round(mult(placketWidth,p.mainStIn.value)-multiple)*multiple+evenNeck;
	}
    
    lengthSlantEdge=Math.sqrt(heightNeckEdge*heightNeckEdge +  widthNeckEdge*widthNeckEdge);
    pickUpSlant= Math.round( mult(lengthSlantEdge,p.mainStIn.value) );  // this is just the front neck.  
    
    //alert( "pickUpSlant one :" + pickUpSlant+ " : "+  lengthSlantEdge)
  
    
    
    //alert( frontNeckShapeStitches + " = " +  frontNeckStitches  + " + 2 *" + begEngeNeckStitches +"placket = " + placketStitches  ) 
        
    
    ragStitches=(frontYoke-neckStitches)/2;
    //alert(frontYoke + " - "+ neckStitches + " = " +ragStitches);
    ragWidth=divide( ragStitches,p.mainStIn.value)
    ragRows=Math.round( (mult(frontArmholeDepth,p.mainRowIn.value)+1)/2 )*2;// make sure enough, neck chops off 1
    
    
// first try-- this usually works.
aveTanTheta= divide( frontArmholeDepth,ragWidth );
aveTanTheta=Math.atan(aveTanTheta)*180/Math.PI;
    

aveRowsBetRag = ragRows/ragStitches; // don't want this more than 2;

if(2.0 < aveRowsBetRag){ one1=2; greater='greater'; } // forces 2,4 shaping instead of 2,3 or 3,4.
else{
    one1 = 1; greater='less'; 
    warning+=" --Armholes are shallow compared to chest. This may be ok, but I the directions for dividing for the placket may need to be adjusted. I haven't coded that yet.--";
 };// permits 1,2 and 2, 3 shaping under circumstances.
   
shapeOps=ragRows/one1 ;
shapeReg=ragStitches+1

smallRegRag=one1*Math.floor(shapeOps/shapeReg)-1;smallRegRagP1=smallRegRag+1
largRegRag=one1*Math.ceil(shapeOps/shapeReg)-1;

largeTimesRag=shapeOps%shapeReg;
smallTimesRag=shapeReg-largeTimesRag-1;

//=== angle checks
//  Test Angle and swap of the angle is bad.  This could happen for narrower necks, or fatter people.

slowTanTheta= divide((smallRegRag+1),p.mainRowIn.value) / divide(1,p.mainStIn.value); 
slowTheta= Math.round(Math.atan(slowTanTheta)*180/Math.PI) ;

fastTanTheta= divide((largRegRag+1),p.mainRowIn.value) / divide(1,p.mainStIn.value); 
fastTheta= Math.round(Math.atan(fastTanTheta)*180/Math.PI);


//alert("slow angle"+ slowTheta +": (  " + smallRegRag+ " rows , " + smallTimesRag+ " times). Fast angle"+ fastTheta + "(" + largRegRag  + " needles , " + largeTimesRag+ " times ) ; average = " + aveTanTheta + " ( "+ greater +" than 1)");


if( (smallRegRag ==0 ) && (slowTanTheta<45)){// swap for fat
    holdRag  =smallRegRag; 	 smallRegRag = largRegRag; 	largRegRag=holdRag;
    holdTimes=smallTimesRag;   smallTimesRag =largeTimesRag;   largeTimesRag=holdTimes

}

remBeforeSmall= neckStitches+smallTimesRag*2;
remSleeveBeforeSmall=sleeveYoke -largeTimesRag*2
remSleeveAfterSmall  =remSleeveBeforeSmall - smallTimesRag*2;  
halfRemSleeve = Math.ceil((remSleeveAfterSmall+1)/2);
raiseNeckRows=2/3*((remSleeveAfterSmall+1)-halfRemSleeve);



p.realBackNeckDepth.value= sub(p.backNeckDepth.value, divide(raiseNeckRows,p.mainRowIn.value));

pickUpSlant +=remSleeveAfterSmall-1; // (under shoots a bit, which is ok.)

//=== angle checks
//  Test Angle and swap of the angle is bad.  This could happen for narrower necks, or fatter people.

slowTanTheta= divide((smallRegRag+1),p.mainRowIn.value) / divide(1,p.mainStIn.value); 
slowTheta= Math.round(Math.atan(slowTanTheta)*180/Math.PI) ;

fastTanTheta= divide((largRegRag+1),p.mainRowIn.value) / divide(1,p.mainStIn.value); 
fastTheta= Math.round(Math.atan(fastTanTheta)*180/Math.PI);


//alert("slow angle"+ slowTheta +": (  " + smallRegRag+ " rows , " + smallTimesRag+ " times). Fast angle"+ fastTheta + "(" + largRegRag  + " needles , " + largeTimesRag+ " times ) ; average = " + aveTanTheta + " ( "+ greater +" than 1)");


if(smallRegRag<0){warning += "This sweater cannot be knit with the current specifications."}


// detects bad angles. 
if( 58 < slowTheta){ 
    warning +=" Your armholes must be awfully deep. I'll write you directions, but this sweater is almost certain to fit badly at the shoulders."    
}



p.tooFewStitches.value =warning;

}

