} // end displayHelp private void onRegression(object sender, EventArgs e) { // because of reset selection button, need to clear the concatenated fields nefore doing regression concatSpecies.Remove(0, concatSpecies.Length); concatLiveDead = ""; concatProduct = ""; // make sure a UOM has been selected if (volType == "") { MessageBox.Show("Please select a valid UOM.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); UnitOfMeasure.Focus(); return; } // endif // make sure at least one speciesGroup was selected int anySelected = rgList.Sum(r => r.rgSelected); if (anySelected == 0) { MessageBox.Show("No species groups selected.\nPlease select at least one group to process.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif MainTitle_TW.Remove(0, MainTitle_TW.Length); MainTitle.Remove(0, MainTitle.Length); // setup title for graph if (topwoodRegress) { MainTitle_TW.Append(volumeToUse); MainTitle_TW.Append(volType); MainTitle.Append(volumeToUse); MainTitle.Append(volType); MainTitle_TW.Append(" (Primary + Secondary)"); MainTitle.Append(" Primary"); } else if (!topwoodRegress) { MainTitle.Append(volumeToUse); MainTitle.Append(volType); MainTitle.Append(" Primary"); } // endif topwood // pull data for species selected List <float> justDBH = new List <float>(); List <double> justVol = new List <double>(); List <double> justVol_TW = new List <double>(); concatLiveDead = ""; concatProduct = ""; concatSpecies.Remove(0, concatSpecies.Length); foreach (RegressGroups rl in rgList) { if (rl.rgSelected == 1) { // pull trees List <TreeCalculatedValuesDO> justTrees = bslyr.getRegressTrees(rl.rgSpecies, rl.rgProduct, rl.rgLiveDead, "M"); // load up arrays foreach (TreeCalculatedValuesDO jt in justTrees) { // load DBH or DRC float jd = new float(); if (jt.Tree.DBH > 0) { jd = jt.Tree.DBH; } else if (jt.Tree.DRC > 0) { jd = jt.Tree.DRC; } justDBH.Add(jd); // load volume for primary regression double jv = new double(); // need primary whether topwood checked or not switch (volType) { case "BDFT": if (volumeToUse == "Gross") { jv = jt.GrossBDFTPP; } else if (volumeToUse == "Net") { jv = jt.NetBDFTPP; } break; case "CUFT": if (volumeToUse == "Gross") { jv = jt.GrossCUFTPP; } else if (volumeToUse == "Net") { jv = jt.NetCUFTPP; } break; case "CORDS": jv = jt.CordsPP; break; } // end switch justVol.Add(jv); if (topwoodRegress) { switch (volType) { case "BDFT": if (volumeToUse == "Gross") { jv = jt.GrossBDFTSP; } else if (volumeToUse == "Net") { jv = jt.NetBDFTSP; } break; case "CUFT": if (volumeToUse == "Gross") { jv = jt.GrossCUFTSP; } else if (volumeToUse == "Net") { jv = jt.NetCUFTSP; } break; case "CORDS": jv = jt.CordsSP; break; } // end switch justVol_TW.Add(jv); } // endif topwood } // end foreach loop on trees // update species/product/livedead for current group updateHeaderInfo(rl); } // endif selected } // end foreach on groups // load arrays to pass to regression float[] DBHarray = new float[justDBH.Count]; double[] VolArray = new double[justVol.Count]; int nthItem = 0; foreach (float jd in justDBH) { DBHarray[nthItem] = jd; nthItem++; } // end foreach loop nthItem = 0; foreach (double jv in justVol) { VolArray[nthItem] = jv; nthItem++; } // end foreach loop // call regression // need to create model code to send for graph title switch (MainTitle.ToString()) { case "GrossCUFT Primary": TitleCode = 1; break; case "NetCUFT Primary": TitleCode = 2; break; case "GrossBDFT Primary": TitleCode = 3; break; case "NetBDFT Primary": TitleCode = 4; break; case "Cords Primary": TitleCode = 5; break; } // end switch on MainTitle // Call local volume library for primary regression if (nthItem < 3) { MessageBox.Show("Too few trees. Need more than two trees\nto run regression analysis.", "WARING", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } GetLocalTable(DBHarray, VolArray, nthItem, TitleCode, ref coef1, ref coef2, ref coef3, ref meanSqEr, ref rSquared, ref ModelCode); // create DBH class list float minDBH = DBHarray.Min(); float maxDBH = DBHarray.Max(); if (ModelCode != 0) { // update regression results updateResults(volType, "Primary", concatSpecies, concatProduct, concatLiveDead, minDBH, maxDBH); } // endif cancel was clicked // then regress secondary if (topwoodRegress) { // add TW to primary for (int j = 0; j < justVol_TW.Count; j++) { justVol[j] += justVol_TW[j]; } // then dump into array to pass to regression Array.Clear(VolArray, 0, VolArray.Length); nthItem = 0; foreach (double jv in justVol) { VolArray[nthItem] = jv; nthItem++; } // end foreach loop // change main title for secondary switch (MainTitle_TW.ToString()) { case "GrossCUFT (Primary + Secondary)": TitleCode = 11; break; case "NetCUFT (Primary + Secondary)": TitleCode = 21; break; case "GrossBDFT (Primary + Secondary)": TitleCode = 31; break; case "NetBDFT (Primary + Secondary)": TitleCode = 41; break; case "Cords (Primary + Secondary)": TitleCode = 51; break; } // end switch on MainTitle // call regression for secondary GetLocalTable(DBHarray, VolArray, nthItem, TitleCode, ref coef1, ref coef2, ref coef3, ref meanSqEr, ref rSquared, ref ModelCode); if (ModelCode != 0) { // min and max DBH will be the same // update results list updateResults(volType, "Secondary", concatSpecies, concatProduct, concatLiveDead, minDBH, maxDBH); } // endif cancel was clicked } // endif topwood // Save results bslyr.SaveRegress(resultsList); bslyr.fileName = fileName; return; } // end onRegression