function calcMasterValuesHK(){

 //alert("raglanBotUpCarMastCalcs.js");
 
// these are the boundary values for the sweater.
p.buttonBandWidth.value = eval(p.bandWidth.value); // 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)
widthOneStitch=divide(1,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=sub(neckWidth,p.bandWidth.value);     
    
    backChestWidth=divide(p.chest.value,2)
    frontChestWidth=sub(backChestWidth,p.bandWidth.value)
	
	bandWidth=eval(p.bandWidth.value);
	//alert(" bandWidth " +bandWidth +" frontChestWidth " +frontChestWidth+" backChestWidth " +backChestWidth)
	

    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 = 1;evenNeck = 1; multiple=2; }// neck odd, body even -- different from pull over.
    else if(p.stitchMult.selectedIndex==1){	evenBody=0; evenNeck = 0; multiple=2; }   
	else{evenBody = 0;evenNeck = 0; multiple=1; }// make it odd.  Fix later.
    
     // later set this with a toggle. 
		//bodyFront=Math.round( (mult(frontChestWidth,p.mainStIn.value)-evenBody)/multiple)*multiple+evenBody;
		//cardigan always has 1 extra stitch to account for band.
		// -1/2 stitch is the seam stitch.
	
	halfBodyFront=Math.round(mult(halfFrontChest-widthOneStitch/2,p.mainStIn.value))+1;// +1 is stitch at opning edges.
	bodyFront= 2*halfBodyFront+1;// the 1 is the seam stitch.
		
    bodyBack= Math.round( (mult(backChestWidth-widthOneStitch,p.mainStIn.value)-evenBody )/multiple )*multiple+(evenBody+1); 
	bodyBackM1=bodyBack-1;
    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;
	halfCastOnFront= Math.floor( ratioHem*mult(halfFrontChest-widthOneStitch/2,p.mainStIn.value))+1;	// don't add the stitch at the edge opening.
	castOnFront=2*halfCastOnFront+1;// 1 is seam stitche.
	
    castOnBack= 	Math.floor( ratioHem*mult( backChestWidth,p.mainStIn.value)/2)*2; 
    castOnBody=castOnFront+castOnBack;
    castOnBodyP1=castOnBody+1;
	
	if(halfCastOnFront%2==0){
			firstStitch="k";   k1p1="* k1, p1; repeat from * end k1. " } 
	else {	firstStitch="p"; ; k1p1="* p1, k1; repeat from * end p1. " }; 
    
   
	halfIncFront=halfBodyFront- halfCastOnFront;  incFront=2*halfIncFront;
    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)/2; // half for cardigan?    
    backYoke=bodyBack-underArmStitches;
	
	firstFrontYoke=frontYoke+halfUnderArmStitches;
	//alert("frontYoke= " + frontYoke + " backYoke= " + backYoke);
    
    sleeveYoke=bicepStitches-underArmStitches;
    firstSleeveYoke=sleeveYoke+halfUnderArmStitchesP1;
//  raglan shaping
//  neck stuff is calculated based on back, and later adjusted for front bindoff.

    neckStitches=Math.round( (mult(neckWidth,p.mainStIn.value)-evenNeck)/multiple)*multiple+evenNeck;
    frontNeckStitches=Math.ceil( (mult(neckWidth,p.mainStIn.value)-evenNeck)/(2*multiple))*multiple+evenNeck ;
    
    edgeNeckStitches=Math.round((neckStitches-frontNeckStitches)/2);// 
    frontNeckStitches = neckStitches-2*edgeNeckStitches; // these the flat part of the shaping projected on the back.
	
	frontFrontNeckStitches=frontYoke-2*edgeNeckStitches;
	
    edgeNeckStitchesM1=edgeNeckStitches-1;     
    frontNeckShapeRows= edgeNeckStitches*2;  // virtually always because I add 2 st every 2 rows.
    begShapeNeckStitches=  edgeNeckStitches+edgeNeckStitches;// this needs to be odd because first pass doesn't have a neck decrease.

// these need to match. 
    frontNeckShapeStitches = neckStitches+ begShapeNeckStitches; // +2 so there are 3 left
	frontFrontNeckShapeStitches=(frontNeckShapeStitches + (2* frontYoke-backYoke))/2; 
	
	firstNeckBindOff=frontFrontNeckShapeStitches-2*edgeNeckStitches;
	//alert("frontNeckshape=" + frontNeckShapeStitches +" : edgeNeckStitche= " + edgeNeckStitches+" : frontNeckShapeStitches " + frontNeckShapeStitches +" : begShapeNeckStitches " + begShapeNeckStitches );
	
    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.
    
 // this will eventaully be button band.
	placketWidth=eval(p.bandWidth.value);
	//placketStitches=2*frontYoke-backYoke;
    
    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=(backYoke-neckStitches)/2;
	
    //alert("backYoke = "+ backYoke + " -  neck stitches"+ neckStitches + " )/2 = " +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;
//alert( 'aveRowsBetRag=  ' + aveRowsBetRag + ' ragRows= ' + ragRows );

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

//alert( 'shapeOps=  ' + shapeOps + ' one1= ' + one1 + ' shapeReg= ' + shapeReg );

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

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

//alert( 'largeTimesRags=  ' + largeTimesRag + ' smallTimesRag= ' + smallTimesRag );

//=== 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;

}

