package com.ng.ngtools.modules;

import com.ng.ngtools.tangible.RefObject;

import javax.swing.*;

public class FlowCal
{
  /** 
   标准孔板流量计算
   
   @param FlowPar
   @param GasPar
   @return 
  */
  public final double OFlowCal(RefObject<NG_Cal.GasPropsSTRUCT> GasPar, RefObject<NG_Cal.FlowParStruct> FlowPar)
  {


    //将压力 温度 差压 当地大气压 压力量程 温度量程 和差压量程都换算到标准计算所使用的单位下的值


    // 考虑膨胀系数后的管道直径
    // 考虑膨胀系数后的喉部直径
    //直径比  
    FlowPar.argValue.dOrificeD = FlowPar.argValue.dOrificeD * (1 + 0.000001 * (FlowPar.argValue.dOrificeMaterial) * (FlowPar.argValue.dTf - 293.15));
    FlowPar.argValue.dPipeD = FlowPar.argValue.dPipeD * (1 + 0.000001 * (FlowPar.argValue.dPipeMaterial) * (FlowPar.argValue.dTf - 293.15));
    FlowPar.argValue.dBeta = FlowPar.argValue.dOrificeD / FlowPar.argValue.dPipeD;

//    FlowPar.argValue.dOrificeD = 150.24;
//    FlowPar.argValue.dPipeD = 259.37;
//    FlowPar.argValue.dBeta = 0.5792;


    //求渐近速度系数 E
    FlowPar.argValue.dE = 1 / Math.pow((1 - Math.pow(FlowPar.argValue.dBeta, 4)), 0.5);
//    FlowPar.argValue.dE = 1.0615;

    //求相对密度系数 FG
    // LiuTiType = 1
    FlowPar.argValue.dFG = Math.pow((1 / GasPar.argValue.dRD_Real), 0.5);
//    FlowPar.argValue.dFG = 1.2531;
    //求流动温度系数 'FT
    FlowPar.argValue.dFT = Math.pow((293.15 / FlowPar.argValue.dTf), 0.5);
//    FlowPar.argValue.dFT = 1.0086;
    //求等熵指数?????????????????????????????????    

    FlowPar.argValue.dKappa = GasPar.argValue.dKappa;
//    FlowPar.argValue.dKappa = 1.357;

    //求动力粘度 dlnd
    FlowPar.argValue.dDViscosity = Dlndjs(FlowPar.argValue.dPf, FlowPar.argValue.dTf, 2, 1);
//    FlowPar.argValue.dDViscosity = 0.01096;

    //求可膨胀系数
    FlowPar.argValue.dDExpCoefficient = KePenZhang_JiSuan(FlowPar.argValue.dPf / 1e6, FlowPar.argValue.dDp, FlowPar.argValue.dBeta, FlowPar.argValue.dKappa, FlowPar.argValue.dCoreType, 0);
//    FlowPar.argValue.dDExpCoefficient = 0.9977;
    //迭代计算流量和流出系数

    double conQvA = 0;
    conQvA = 0.0000031795 * (1530000.0D * GasPar.argValue.dRD_Real / (FlowPar.argValue.dDViscosity * FlowPar.argValue.dOrificeD)) * FlowPar.argValue.dE * Math.pow(FlowPar.argValue.dOrificeD, 2) * GasPar.argValue.dFpv * FlowPar.argValue.dFG * FlowPar.argValue.dDExpCoefficient * FlowPar.argValue.dFT * Math.sqrt(FlowPar.argValue.dPf * FlowPar.argValue.dDp / 1e6);
    double[] XQv = new double[4];
    double[] CQv = new double[4];
    double[] dQv = new double[4];
    double Qn = 0;
    int n = 0;
    XQv[0] = 1000000.0F;
    boolean xhFlag=true;
    _100000:

    while(xhFlag) {
        for (n = 1; n <= 2; n++) {
            CQv[n] = C_JiSuan(FlowPar.argValue.dOrificeD, FlowPar.argValue.dBeta, XQv[n - 1], conQvA, FlowPar.argValue.dPtmode, FlowPar.argValue.dCoreType, 0);
            XQv[n] = conQvA * CQv[n];
            dQv[n] = XQv[n] - XQv[n - 1];
        }
        if (XQv[2] == XQv[1] || dQv[2] == dQv[1]) {
            Qn = conQvA * FlowPar.argValue.dDViscosity * FlowPar.argValue.dOrificeD * CQv[2] / (1530000.0D * GasPar.argValue.dRD_Real);
            //管道雷诺数
            FlowPar.argValue.dRnPipe = XQv[2];
            //流出系数
            FlowPar.argValue.dCd = CQv[2];

        }
        if (Math.abs((conQvA - XQv[2] / CQv[1]) / conQvA) > 0.00000000000000005) {
            XQv[0] = XQv[n - 1] - dQv[n - 1] * ((XQv[n - 1] - XQv[n - 2]) / (dQv[n - 1] - dQv[n - 2]));
//C# TO JAVA CONVERTER TODO TASK: There is no 'goto' in Java:
            continue _100000;
        }
        else
        {
            xhFlag=false;
        }
    }

    //孔板锐利度系数Bk
    FlowPar.argValue.dOrificeSharpness = 1;
    if (FlowPar.argValue.dCoreType == 0)
    {
      FlowPar.argValue.dBk = (FlowPar.argValue.dOrificeSharpness == 0) ? (BkTable(FlowPar.argValue.dOrificeRk, FlowPar.argValue.dOrificeD, 1)) : (FlowPar.argValue.dOrificeSharpness);
    }
    else
    {
      FlowPar.argValue.dBk = 1;
    }


    //管道粗糙度系数 Gme
    FlowPar.argValue.dRoughNessPipe = CcdXsjs(FlowPar.argValue.dPipeType, FlowPar.argValue.dPipeD, FlowPar.argValue.dBeta, FlowPar.argValue.dRnPipe);
    //修正后的流出系数
    FlowPar.argValue.dCd = FlowPar.argValue.dCd * FlowPar.argValue.dBk * FlowPar.argValue.dRoughNessPipe;
    //标况体积流量 m³、s
    FlowPar.argValue.dVFlowb = Qn * FlowPar.argValue.dBk * FlowPar.argValue.dRoughNessPipe;
    //工况体积流量
    FlowPar.argValue.dVFlowf = FlowConvert_BaseToWork(FlowPar, GasPar);
    //标况质量流量
    FlowPar.argValue.dMFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dRhob;
    //标况能量流量
    FlowPar.argValue.dEFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dHhvv;
    //管道内天然气流速
    FlowPar.argValue.dVelocityFlow = FlowPar.argValue.dVFlowf / (3.1415926 * Math.pow((FlowPar.argValue.dPipeD / 2000), 2));
    //压力损失
    FlowPar.argValue.dPressLost = YaLiSunShi(FlowPar.argValue.dCd, FlowPar.argValue.dBeta, FlowPar.argValue.dDp, FlowPar.argValue.dCoreType);

    return FlowPar.argValue.dVFlowb;

  }

  /** 
   标准孔板流量计算
   
   @param GasPar
   @param FlowPar
   @return 
  */
  public final double SdFlowCal(RefObject<NG_Cal.GasPropsSTRUCT> GasPar, RefObject<NG_Cal.FlowParStruct> FlowPar)
  {
    //工况体积流量 m³、s
    FlowPar.argValue.dVFlowf = FlowPar.argValue.dPulseNum / FlowPar.argValue.dMeterFactor;

    //标况体积流量 m³、s
    FlowPar.argValue.dVFlowb = FlowConvert_WorkToBase(FlowPar, GasPar);

    //标况质量流量
    FlowPar.argValue.dMFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dRhob;
    //标况能量流量
    FlowPar.argValue.dEFlowb = FlowPar.argValue.dVFlowb * GasPar.argValue.dHhvm;


    return FlowPar.argValue.dVFlowb;

  }

  /** 
   天然气音速喷嘴流量计算
   
   @return 
  */
  public final double NozellFLowCal(RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> ptAGA10, RefObject<com.ng.ngtools.modules.NG_Cal.FlowParStruct> flPar)
  {
    double dAnt; // 喷嘴喉部面积
    //double dCR;//临界流系数
    double dP1Z; //滞止压力
    double dT1Z; //滞止温度
    //double dPbeta;//上下游压力比
    double dDcorrect; // 考虑膨胀系数后的管道直径
    double ddcorrect; // 考虑膨胀系数后的喉部直径
    double dBeta; //直径比
    double dQm;
    try
    {
      ddcorrect = flPar.argValue.dOrificeD * (1 + 0.000001 * (flPar.argValue.dOrificeMaterial) * (flPar.argValue.dTf - 293.15));
      dDcorrect = flPar.argValue.dPipeD * (1 + 0.000001 * (flPar.argValue.dOrificeMaterial) * (flPar.argValue.dTf - 293.15));
      dBeta = ddcorrect / dDcorrect;
      dAnt = 3.1415926 * (ddcorrect / 2) * (ddcorrect / 2);
      //ptNGcal.SOS(ref ptAGA10);

      //dCR = ptAGA10.dCstar * Math.Sqrt(ptAGA10.dZf);
      dP1Z = flPar.argValue.dPf * (1 + ptAGA10.argValue.dKappa / 2 * Math.pow((2 / (ptAGA10.argValue.dKappa + 1)), ((ptAGA10.argValue.dKappa + 1) / (ptAGA10.argValue.dKappa - 1))) * Math.pow(dBeta, 4));
      dT1Z = flPar.argValue.dTf * (1 + (ptAGA10.argValue.dKappa - 1) / 2 * (2 / Math.pow((ptAGA10.argValue.dKappa + 1), ((ptAGA10.argValue.dKappa + 1) / (ptAGA10.argValue.dKappa - 1)))) * Math.pow(dBeta, 4));
      // dQm = dAnt * flPar.dCd * ptAGA10.dCstar * dP1Z / Math.Sqrt(8314.51 * dT1Z / ptAGA10.dMrx);
      dQm = dAnt * flPar.argValue.dCd * ptAGA10.argValue.dCstar * Math.sqrt(ptAGA10.argValue.dZf * dP1Z * ptAGA10.argValue.dRhof);

      if (dBeta > 0.25)
      {
        dQm = dQm * BetaG25(dP1Z, dT1Z, dBeta, ptAGA10);
      }
      flPar.argValue.dMFlowb = dQm;
      flPar.argValue.dVFlowb = flPar.argValue.dMFlowb / ptAGA10.argValue.dRhob;
      //标况能量流量
      flPar.argValue.dEFlowb = flPar.argValue.dVFlowb * ptAGA10.argValue.dHhvm;
      flPar.argValue.dVFlowf = FlowConvert_BaseToWork(flPar, ptAGA10);
      return flPar.argValue.dVFlowb;
    }
    catch (RuntimeException ex)
    {
      return 0.0;
    }
  }

  private double BetaG25(double P0, double T0, double BetaB, RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> ptAGA10)
  {
    double[] nik0 = new double[9];
    double[] Sik0 = new double[9];
    double[] Tik0 = new double[9];
    double[] nik1 = new double[9];
    double[] Sik1 = new double[9];
    double[] Tik1 = new double[9];
    double C0 = 0;
    double C1 = 0;
    double Pai = 0;
    double Tuo = 0;
    double b = 0;
    double F0 = 0;
    double F1 = 0;
    double Rf = 0.65;
    // 直径比大于0.25的修正因子
    nik0[0] = 1.068826e-3;
    nik0[1] = 1.199593e-2;
    nik0[2] = -1.48292e-3;
    nik0[3] = 2.764799e-4;
    nik0[4] = 7.920711e-5;
    nik0[5] = 1.11278e-3;
    nik0[6] = -6.815626e-5;
    nik0[7] = 3.86249e-8;

    nik1[0] = -3.46148e-3;
    nik1[1] = 5.28029e-3;
    nik1[2] = 1.195016e-2;
    nik1[3] = 1.664232e-3;
    nik1[4] = 1.159371e-3;
    nik1[5] = 7.260461e-3;
    nik1[6] = -7.541933e-4;
    nik1[7] = 2.613967e-7;

    Sik0[0] = 0;
    Sik0[1] = 0;
    Sik0[2] = 0.5;
    Sik0[3] = 1;
    Sik0[4] = 2;
    Sik0[5] = 3;
    Sik0[6] = 5;
    Sik0[7] = 10;

    Sik1[0] = 0;
    Sik1[1] = 0;
    Sik1[2] = 0;
    Sik1[3] = 1;
    Sik1[4] = 1.5;
    Sik1[5] = 3;
    Sik1[6] = 5;
    Sik1[7] = 10;

    Tik0[0] = -1;
    Tik0[1] = 0;
    Tik0[2] = -6;
    Tik0[3] = -1;
    Tik0[4] = -2;
    Tik0[5] = -8;
    Tik0[6] = -10;
    Tik0[7] = -18;

    Tik1[0] = -3;
    Tik1[1] = -1;
    Tik1[2] = 0;
    Tik1[3] = -2;
    Tik1[4] = -4;
    Tik1[5] = -10;
    Tik1[6] = -12;
    Tik1[7] = -15;

    Pai = P0 / (ptAGA10.argValue.Pc * 1000000);
    Tuo = T0 / ptAGA10.argValue.TC;
    for (int i = 0; i <= 7; i += 1)
    {
      C0 = C0 + nik0[i] * Math.pow(Pai, Sik0[i]) * Math.pow(Tuo, Tik0[i]);
      C1 = C1 + nik1[i] * Math.pow(Pai, Sik1[i]) * Math.pow(Tuo, Tik1[i]);
    }
    b = 25.879 * Math.pow(BetaB, 6) - 32.693 * Math.pow(BetaB, 5) + 34.276 * Math.pow(BetaB, 4) - 6.0199 * Math.pow(BetaB, 3) - 1.1156 * Math.pow(BetaB, 2) - 0.1122 * BetaB + 0.0047;
    F0 = 1 + b * C0;
    F1 = 1 + b * C1;
    return (1 - Rf) * F0 + Rf * F1;
  }
  /** 
   材料膨胀系数计算
   
   @param tempCaiLiao
   @return 
  */
  public static double CaiLiaoPzxs(int tempCaiLiao)
  {
    double CaiLiaoPzxs = 0;
    // 孔板和管道材料的膨胀系数
    // 0 A3、15号钢
    // 1 10 号钢
    // 2 20 号钢
    // 3 45 号钢
    // 4 1 Cr13?2Cr13
    // 5 Cr17
    // 6 12 CrMoV
    // 7 10 CrMo910
    // 8 Cr6SiMo
    // 9 X20CrMoV121
    // 10 1 Cr18Ni9Ti
    // 11 普通碳钢
    // 12 工业用铜
    // 13 黄铜
    // 14 红铜
    switch (tempCaiLiao)
    {
      case 0:
        CaiLiaoPzxs = 11.75;
        break;

      case 1:
        CaiLiaoPzxs = 11.6;
        break;

      case 2:
        CaiLiaoPzxs = 11.16;
        break;

      case 3:
        CaiLiaoPzxs = 11.59;
        break;

      case 4:
        CaiLiaoPzxs = 10.5;
        break;

      case 5:
        CaiLiaoPzxs = 10D;
        break;

      case 6:
        CaiLiaoPzxs = 10.2;
        break;

      case 7:
        CaiLiaoPzxs = 15.5;
        break;

      case 8:
        CaiLiaoPzxs = 11.5;
        break;

      case 9:
        CaiLiaoPzxs = 10.8;
        break;

      case 10:
        CaiLiaoPzxs = 16.6;
        break;

      case 11:
        CaiLiaoPzxs = 11.4;
        break;

      case 12:
        CaiLiaoPzxs = 16.55;
        break;

      case 13:
        CaiLiaoPzxs = 17.8;
        break;

      case 14:
        CaiLiaoPzxs = 17.2;
        break;
    }
    return CaiLiaoPzxs;
  }

  /** 
   计算重复性
   
   @param data
   @param DataAver
   @return 
  */

  public static double DataEr(RefObject<Double> DataAver, double[] data)
  {
      return DataEr(DataAver, data, 0);
  }

//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
//ORIGINAL LINE: public static double DataEr(ref double DataAver, double[] data, int Num = 0)
  public static double DataEr(RefObject<Double> DataAver, double[] data, int Num) // = 0.0
  {
    double DataEr = 0;
    int n = 0;
    int i = 0;
    double DataSum = 0;
    // 重复性计算

    if (Num == 0)
    {
      n = data.length - 1 + 1;
    }
    else
    {
      n = Num;
    }
    if (n <= 1)
    {
      return DataEr;
    }
    DataSum = 0;
    for (i = 0; i <= n - 1; i += 1)
    {
      DataSum = DataSum + data[i];
    }
    DataAver.argValue = DataSum / n;

    DataSum = 0;
    for (i = 0; i <= n - 1; i += 1)
    {
      DataSum = DataSum + Math.pow((data[i] - DataAver.argValue), 2);
    }

    DataSum = Math.sqrt(DataSum / (n - 1));

    DataEr = DataSum * 100 / DataAver.argValue; // 重复性
    return DataEr;
  }
  /** 
   计算平均值
   
   @param data
   @return 
  */
  public static double DataAVG(double[] data)
  {
    double DataAVG = 0;
    int n = 0;
    int i = 0;
    double DataSum = 0;
    // 平均值
    DataAVG = 0;
    n = data.length - 1 + 1;
    DataSum = 0;
    for (i = 0; i <= n - 1; i += 1)
    {
      DataSum = DataSum + data[i];
    }
    DataAVG = DataSum / n;

    return DataAVG;
  }

  /** 
   获取数组中的最大值
   
   @param MyArray
   @param NumMin
   @return 
  */
  public static double GetMax(double[] MyArray, RefObject<Double> NumMin)
  {
    int gIterations = 0;
    int Index = 0;
    double temp = 0;
    int NextElement = 0;
    // 获得一个数组中的最大值
    NextElement = 0;
    while ((NextElement < MyArray.length - 1))
    {
      Index = MyArray.length - 1;
      while ((Index > NextElement))
      {
        if (MyArray[Index] >= MyArray[Index - 1])
        {
          temp = MyArray[Index];
          MyArray[Index] = MyArray[Index - 1];
          MyArray[Index - 1] = temp;
        }
        Index = Index - 1;
        gIterations = gIterations + 1;
      }
      NextElement = NextElement + 1;
      gIterations = gIterations + 1;
    }
    NumMin.argValue = MyArray[MyArray.length - 1];
    return MyArray[0];
  }

  // #########################################################################
  // ######################'流量转换  标况转工况##############################
  // ########################################################################
  public static double FlowConvert_BaseToWork(RefObject<NG_Cal.FlowParStruct> flPar, RefObject<NG_Cal.GasPropsSTRUCT> ptAGA10)
  {
    double tempPn = 0;
    double tempTn = 0;

    try
    {

      if (ptAGA10.argValue.dZf == 0 || ptAGA10.argValue.dZb == 0)
      {
        return 0.0;
      }


      switch (ptAGA10.argValue.dCbtj)
      {
        case 2:
          tempPn = 101325;
          tempTn = 273.15;
          break;

        case 1:
          tempPn = 101325;
          tempTn = 288.15;
          break;

        case 0:
          tempPn = 101325;
          tempTn = 293.15;
          break;

        case 3:
          tempPn = 10155981;
          tempTn = 288.7055555;
          break;
      }


      flPar.argValue.dVFlowf = flPar.argValue.dVFlowb * (tempPn * flPar.argValue.dTf * ptAGA10.argValue.dZf) / (flPar.argValue.dPf * tempTn * ptAGA10.argValue.dZb);
      return flPar.argValue.dVFlowf;
      // WARNING: ErrDo: is not supported 
    }
    catch (RuntimeException exc)
    {
      return 0.0;

    }
  }

  // #########################################################################
  // ######################流量转换工况转标况##############################
  // ########################################################################
  public static double FlowConvert_WorkToBase(RefObject<NG_Cal.FlowParStruct> flPar, RefObject<NG_Cal.GasPropsSTRUCT> ptAGA10)
  {
    double tempPn = 0;
    double tempTn = 0;

    // WARNING: On Error GOTO ErrDo is not supported
    try
    {

      switch (ptAGA10.argValue.dCbtj)
      {
        case 2:
          tempPn = 101325;
          tempTn = 273.15;
          break;

        case 1:
          tempPn = 101325;
          tempTn = 288.15;
          break;

        case 0:
          tempPn = 101325;
          tempTn = 293.15;
          break;

        case 3:
          tempPn = 0.10155981;
          tempTn = 288.7055555;
          break;
      }
      flPar.argValue.dVFlowb = flPar.argValue.dVFlowf * (flPar.argValue.dPf * tempTn * ptAGA10.argValue.dZb) / (tempPn * flPar.argValue.dTf * ptAGA10.argValue.dZf);
      return flPar.argValue.dVFlowb;
      // WARNING: ErrDo: is not supported 
    }
    catch (RuntimeException exc)
    {
      return 0.0;
    }

  }
  //压力损失计算
  public final double YaLiSunShi(double tempLiuChuXiShu, double tempZjb, double tempDp, int JieLiuZhuangZhi)
  {
    double ylss = 0;
    switch (JieLiuZhuangZhi)
    {
      case 0:
        ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2)));
        break;
      case 1:
        ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2)));
        break;
      case 2:
        ylss = (tempDp * (Math.sqrt(1 - tempZjb) - tempLiuChuXiShu * Math.pow(tempZjb, 2)) / (Math.sqrt(1 - tempZjb) + tempLiuChuXiShu * Math.pow(tempZjb, 2)));
        break;
    }
    return ylss;
  }
  //查表计算粘度μ
  // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#.
  private final double[][] Dlndjs_Dlnd_Data = new double[8][11];
  private final double[] Dlndjs_Dlnd_T = new double[8];
  private final double[] Dlndjs_Dlnd_P = new double[11];

  public final double Dlndjs(double tempP_jy, double tempT, int PU, int TU)
  {
    // static double[,] Dlnd_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_Data. Local static variables are not supported in C#.
    // static double[] Dlnd_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_T. Local static variables are not supported in C#.
    // static double[] Dlnd_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Dlndjs_Dlnd_P. Local static variables are not supported in C#.
    double s1 = 0;
    double s2 = 0;
    double ky = 0;
    double kx = 0;
    int i = 0;
      int m = 0;
      int n = 0;
    //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
    Dlndjs_Dlnd_T[0] = -15 + 273.15;
    Dlndjs_Dlnd_T[1] = 0 + 273.15;
    Dlndjs_Dlnd_T[2] = 15 + 273.15;
    Dlndjs_Dlnd_T[3] = 30 + 273.15;
    Dlndjs_Dlnd_T[4] = 45 + 273.15;
    Dlndjs_Dlnd_T[5] = 60 + 273.15;
    Dlndjs_Dlnd_T[6] = 75 + 273.15;
    Dlndjs_Dlnd_T[7] = 90 + 273.15;

    Dlndjs_Dlnd_P[0] = 0.1F;
    Dlndjs_Dlnd_P[1] = 1;
    Dlndjs_Dlnd_P[2] = 2;
    Dlndjs_Dlnd_P[3] = 3;
    Dlndjs_Dlnd_P[4] = 4;
    Dlndjs_Dlnd_P[5] = 5;
    Dlndjs_Dlnd_P[6] = 6;
    Dlndjs_Dlnd_P[7] = 7;
    Dlndjs_Dlnd_P[8] = 8;
    Dlndjs_Dlnd_P[9] = 9;
    Dlndjs_Dlnd_P[10] = 10;
    Dlndjs_Dlnd_Data[0][0] = 976;
    Dlndjs_Dlnd_Data[1][0] = 1027;
    Dlndjs_Dlnd_Data[2][0] = 1071;
    Dlndjs_Dlnd_Data[3][0] = 1123;
    Dlndjs_Dlnd_Data[4][0] = 1167;
    Dlndjs_Dlnd_Data[5][0] = 1213;
    Dlndjs_Dlnd_Data[6][0] = 1260;
    Dlndjs_Dlnd_Data[7][0] = 1303;
    Dlndjs_Dlnd_Data[0][1] = 991;
    Dlndjs_Dlnd_Data[1][1] = 1040;
    Dlndjs_Dlnd_Data[2][1] = 1082;
    Dlndjs_Dlnd_Data[3][1] = 1135;
    Dlndjs_Dlnd_Data[4][1] = 1178;
    Dlndjs_Dlnd_Data[5][1] = 1224;
    Dlndjs_Dlnd_Data[6][1] = 1270;
    Dlndjs_Dlnd_Data[7][1] = 1312;
    Dlndjs_Dlnd_Data[0][2] = 1014;
    Dlndjs_Dlnd_Data[1][2] = 1063;
    Dlndjs_Dlnd_Data[2][2] = 1106;
    Dlndjs_Dlnd_Data[3][2] = 1153;
    Dlndjs_Dlnd_Data[4][2] = 1196;
    Dlndjs_Dlnd_Data[5][2] = 1239;
    Dlndjs_Dlnd_Data[6][2] = 1281;
    Dlndjs_Dlnd_Data[7][2] = 1323;
    Dlndjs_Dlnd_Data[0][3] = 1044;
    Dlndjs_Dlnd_Data[1][3] = 1091;
    Dlndjs_Dlnd_Data[2][3] = 1127;
    Dlndjs_Dlnd_Data[3][3] = 1174;
    Dlndjs_Dlnd_Data[4][3] = 1216;
    Dlndjs_Dlnd_Data[5][3] = 1257;
    Dlndjs_Dlnd_Data[6][3] = 1297;
    Dlndjs_Dlnd_Data[7][3] = 1338;
    Dlndjs_Dlnd_Data[0][4] = 1073;
    Dlndjs_Dlnd_Data[1][4] = 1118;
    Dlndjs_Dlnd_Data[2][4] = 1149;
    Dlndjs_Dlnd_Data[3][4] = 1195;
    Dlndjs_Dlnd_Data[4][4] = 1236;
    Dlndjs_Dlnd_Data[5][4] = 1275;
    Dlndjs_Dlnd_Data[6][4] = 1313;
    Dlndjs_Dlnd_Data[7][4] = 1352;
    Dlndjs_Dlnd_Data[0][5] = 1114;
    Dlndjs_Dlnd_Data[1][5] = 1151;
    Dlndjs_Dlnd_Data[2][5] = 1180;
    Dlndjs_Dlnd_Data[3][5] = 1224;
    Dlndjs_Dlnd_Data[4][5] = 1261;
    Dlndjs_Dlnd_Data[5][5] = 1297;
    Dlndjs_Dlnd_Data[6][5] = 1333;
    Dlndjs_Dlnd_Data[7][5] = 1372;
    Dlndjs_Dlnd_Data[0][6] = 1156;
    Dlndjs_Dlnd_Data[1][6] = 1185;
    Dlndjs_Dlnd_Data[2][6] = 1211;
    Dlndjs_Dlnd_Data[3][6] = 1253;
    Dlndjs_Dlnd_Data[4][6] = 1287;
    Dlndjs_Dlnd_Data[5][6] = 1320;
    Dlndjs_Dlnd_Data[6][6] = 1352;
    Dlndjs_Dlnd_Data[7][6] = 1391;
    Dlndjs_Dlnd_Data[0][7] = 1207;
    Dlndjs_Dlnd_Data[1][7] = 1230;
    Dlndjs_Dlnd_Data[2][7] = 1250;
    Dlndjs_Dlnd_Data[3][7] = 1289;
    Dlndjs_Dlnd_Data[4][7] = 1318;
    Dlndjs_Dlnd_Data[5][7] = 1346;
    Dlndjs_Dlnd_Data[6][7] = 1374;
    Dlndjs_Dlnd_Data[7][7] = 1412;
    Dlndjs_Dlnd_Data[0][8] = 1261;
    Dlndjs_Dlnd_Data[1][8] = 1276;
    Dlndjs_Dlnd_Data[2][8] = 1289;
    Dlndjs_Dlnd_Data[3][8] = 1324;
    Dlndjs_Dlnd_Data[4][8] = 1350;
    Dlndjs_Dlnd_Data[5][8] = 1373;
    Dlndjs_Dlnd_Data[6][8] = 1396;
    Dlndjs_Dlnd_Data[7][8] = 1432;
    Dlndjs_Dlnd_Data[0][9] = 1331;
    Dlndjs_Dlnd_Data[1][9] = 1331;
    Dlndjs_Dlnd_Data[2][9] = 1335;
    Dlndjs_Dlnd_Data[3][9] = 1366;
    Dlndjs_Dlnd_Data[4][9] = 1385;
    Dlndjs_Dlnd_Data[5][9] = 1403;
    Dlndjs_Dlnd_Data[6][9] = 1424;
    Dlndjs_Dlnd_Data[7][9] = 1456;
    Dlndjs_Dlnd_Data[0][10] = 1405;
    Dlndjs_Dlnd_Data[1][10] = 1389;
    Dlndjs_Dlnd_Data[2][10] = 1383;
    Dlndjs_Dlnd_Data[3][10] = 1409;
    Dlndjs_Dlnd_Data[4][10] = 1421;
    Dlndjs_Dlnd_Data[5][10] = 1435;
    Dlndjs_Dlnd_Data[6][10] = 1451;
    Dlndjs_Dlnd_Data[7][10] = 1482;

    if (tempT < Dlndjs_Dlnd_T[0])
    {
      tempT = Dlndjs_Dlnd_T[0];
    }
    if (tempT > Dlndjs_Dlnd_T[7])
    {
      tempT = Dlndjs_Dlnd_T[7];
    }
    if (tempP_jy < Dlndjs_Dlnd_P[0])
    {
      tempP_jy = Dlndjs_Dlnd_P[0];
    }
    if (tempP_jy > Dlndjs_Dlnd_P[10])
    {
      tempP_jy = Dlndjs_Dlnd_P[10];
    }

    for (  i = 0; i <= 6; i++)
    {
      if (tempT >= Dlndjs_Dlnd_T[i] && tempT <= Dlndjs_Dlnd_T[i + 1])
      {
        m = i;
        break;
      }
    }

    for (i = 0; i <= 9; i++)
    {
      if (tempP_jy >= Dlndjs_Dlnd_P[i] && tempP_jy <= Dlndjs_Dlnd_P[i + 1])
      {
        n = i;
        break;
      }
    }

    if (Dlndjs_Dlnd_P[n + 1] - Dlndjs_Dlnd_P[n] != 0)
    {
      ky = (tempP_jy - Dlndjs_Dlnd_P[n]) / (Dlndjs_Dlnd_P[n + 1] - Dlndjs_Dlnd_P[n]);
    }
    else
    {
      ky = 0;
    }
    if (Dlndjs_Dlnd_T[m + 1] - Dlndjs_Dlnd_T[m] != 0)
    {
      kx = (tempT - Dlndjs_Dlnd_T[m]) / (Dlndjs_Dlnd_T[m + 1] - Dlndjs_Dlnd_T[m]);
    }
    else
    {
      kx = 0;
    }
    s1 = Dlndjs_Dlnd_Data[m][n] + (Dlndjs_Dlnd_Data[m][n + 1] - Dlndjs_Dlnd_Data[m][n]) * ky;
    s2 = Dlndjs_Dlnd_Data[m + 1][n] + (Dlndjs_Dlnd_Data[m + 1][n + 1] - Dlndjs_Dlnd_Data[m + 1][n]) * ky;
    return (s1 + (s2 - s1) * kx) / 100000.0D;
  }
  //可膨胀系数计算
  private double KePenZhang_JiSuan(double tempP_jy_MPa, double tempDp_Pa, double tempZjb, double tempDszs, int JIeliuType, int JiSuanBiaoZhun) // 求可膨胀系数
  {
    double returnValue = 0;
    //0标准孔板
    //1ISA1932喷嘴
    //2长径喷嘴
    //3文丘里喷嘴
    //4粗铸收缩段经典文丘里管
    //5机械加工收缩段经典文丘里管
    //6粗焊铁板收缩段经典文丘里管
    //7 1/4圆孔板

    double tuo = 0;
    switch (JIeliuType)
    {
      case 0: //孔板流量计算
        switch (JiSuanBiaoZhun)
        {
          case 0: //6143-2004
            tuo = (tempP_jy_MPa * 1000000.0D - tempDp_Pa) / (tempP_jy_MPa * 1000000.0D);
            returnValue = 1 - (0.351 + 0.256 * Math.pow(tempZjb, 4) + 0.93 * Math.pow(tempZjb, 8)) * (1 - Math.pow(tuo, (1 / tempDszs)));
            break;
          case 1: //6143-1996
            returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs);
            break;

        }
        break;
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
        switch (JiSuanBiaoZhun)
        {
          case 0:

            //标准喷嘴  iso5167-2002
            tuo = (tempP_jy_MPa * 10000000.0D - tempDp_Pa) / (tempP_jy_MPa * 10000000.0D);
            returnValue = Math.pow((((tempDszs * Math.pow(tuo, (2 / tempDszs))) / (tempDszs - 1)) * ((1 - Math.pow(tempZjb, 4)) / (1 - Math.pow(tempZjb, 4) * Math.pow(tuo, (2 / tempDszs)))) * ((1 - Math.pow(tuo, ((tempDszs - 1) / tempDszs))) / (1 - tuo))), 0.5);
            break;

          case 1: //iso5167-93
            returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs);
            break;
        }
        break;
      case 7: //1/4圆孔板
        returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs);
        break;
      case 8: //锥形入口孔板
        tuo = (tempP_jy_MPa * 1000000.0D - tempDp_Pa) / (tempP_jy_MPa * 1000000.0D);
        returnValue = 1 - (0.351 + 0.256 * Math.pow(tempZjb, 4) + 0.93 * Math.pow(tempZjb, 8)) * (1 - Math.pow(tuo, (1 / tempDszs)));

        tuo = (tempP_jy_MPa * 10000000.0D - tempDp_Pa) / (tempP_jy_MPa * 10000000.0D);

        returnValue = 0.5 * (returnValue + Math.pow((((tempDszs * Math.pow(tuo, (2 / tempDszs))) / (tempDszs - 1)) * ((1 - Math.pow(tempZjb, 4)) / (1 - Math.pow(tempZjb, 4) * Math.pow(tuo, (2 / tempDszs)))) * ((1 - Math.pow(tuo, ((tempDszs - 1) / tempDszs))) / (1 - tuo))), 0.5));
        break;
      case 9: //偏心孔板
        returnValue = 1 - (0.41 + 0.35 * Math.pow(tempZjb, 4)) * tempDp_Pa / (1000000 * tempP_jy_MPa * tempDszs);
        break;

    }
    return returnValue;
  }
  //流出系数计算
  public final double C_JiSuan(double tempGj, double tempZjb, double tempReD, double tempconQvA, int tempQyfs, int JieLiuType, int JiSuanBiaoZhun)
  {
    double returnValue = 0;
    //流出系数计算函数
    //输入：直径比，雷诺数，取压方式，节流装置类型，计算采用标准
    //输出:流出系数

    //jieliutype

    //0标准孔板
    //1ISA1932喷嘴
    //2长径喷嘴
    //3文丘里喷嘴
    //4粗铸收缩段经典文丘里管
    //5机械加工收缩段经典文丘里管
    //6粗焊铁板收缩段经典文丘里管

    double L1 = 0;
    double L2 = 0;
    switch (JieLiuType)
    {
      case 0: //孔板
        switch (tempQyfs)
        {
          case 0:
            L1 = 25.4 / tempGj;
            L2 = L1;
            break;
          case 1:
            L1 = 0;
            L2 = 0;
            break;
          case 2:
            L1 = 1;
            L2 = 0.47F;
            break;
        }

        switch (JiSuanBiaoZhun)
        {
          case 0: //6143-2004
            if (tempGj >= 71.12)
            {
              returnValue = 0.5961 + 0.0261 * Math.pow(tempZjb, 2) - 0.216 * Math.pow(tempZjb, 8) + 0.000521 * Math.pow((1000000.0D * tempZjb / tempReD), 0.7) + (0.0188 + 0.0063 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 3.5) * Math.pow((1000000.0D / tempReD), 0.3) + (0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1)) * (1 - 0.11 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * (Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1))) - 0.031 * (2 * L2 / (1 - tempZjb) - 0.8 * Math.pow((2 * L2 / (1 - tempZjb)), 1.1)) * Math.pow(tempZjb, 1.3);

            }
            else if (tempGj < 71.12)
            {
              returnValue = (0.5961 + 0.0261 * Math.pow(tempZjb, 2) - 0.216 * Math.pow(tempZjb, 8) + 0.000521 * Math.pow((1000000.0D * tempZjb / tempReD), 0.7) + (0.0188 + 0.0063 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 3.5) * Math.pow((1000000.0D / tempReD), 0.3) + (0.043 + 0.08 * Math.exp(-10 * L1) - 0.123 * Math.exp(-7 * L1)) * (1 - 0.11 * Math.pow((19000 * tempZjb / tempReD), 0.8)) * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.031 * (2 * L2 / (1 - tempZjb) - 0.8 * Math.pow((2 * L2 * (1 - tempZjb)), 1.1)) * Math.pow(tempZjb, 1.3) + 0.011 * (0.75 - tempZjb) * (2.8 - tempGj / 25.4));
            }
            break;
          case 1: //6143-1996
            if (0.09 * L1 >= 0.039)
            {
              returnValue = 0.5959 + 0.0312 * Math.pow(tempZjb, (2.1)) - 0.184 * Math.pow(tempZjb, 8) + 0.0029 * Math.pow(tempZjb, 2.5) * Math.pow((1000000.0D / tempReD), 0.75) + 0.039 * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.0337 * L1 * Math.pow(tempZjb, 3);
            }
            else if (0.09 * L1 < 0.039)
            {
              returnValue = (0.5959 + 0.0312 * Math.pow(tempZjb, (2.1)) - 0.184 * Math.pow(tempZjb, 8) + 0.0029 * Math.pow(tempZjb, 2.5) * Math.pow((1000000.0D / tempReD), 0.75) + 0.09 * L1 * Math.pow(tempZjb, 4) * Math.pow((1 - Math.pow(tempZjb, 4)), (-1)) - 0.0337 * L1 * Math.pow(tempZjb, 3));
            }
            break;
        }
        break;



      case 1: //ISA1932喷嘴
        returnValue = (0.99 - 0.2262 * Math.pow(tempZjb, 4.1) - (0.00175 * Math.pow(tempZjb, 2) - 0.0033 * Math.pow(tempZjb, 4.15)) * (1000000.0D / Math.pow(tempReD, 1.15)));
        break;

      case 2: //长径喷嘴
        returnValue = (0.9965 - 0.00653 * Math.pow(tempZjb, 0.5) * Math.pow((1000000.0D / tempReD), 0.5));
        break;
      case 3: //文丘里喷嘴
        returnValue = (0.9858 - 0.196 * Math.pow(tempZjb, 4.5));
        break;
      case 4: //粗铸收缩段经典文丘里管
        returnValue = (0.984F);
        break;
      case 5: //机械加工收缩段经典文丘里管
        returnValue = (0.995F);
        break;
      case 6: //粗焊铁板收缩段经典文丘里管
        returnValue = (0.985F);
        break;
      case 7: //1/4圆孔板
        returnValue = 0.73823 - 0.3309 * tempZjb - 1.1615 * Math.pow(tempZjb, 2) + 1.5084 * Math.pow(tempZjb, 3);
        break;
      case 8: //锥形入口孔板
        returnValue = (0.734F);
        break;
      case 9: //偏心孔板
        returnValue = 0.9355 - 1.6889 * tempZjb + 3.0428 * Math.pow(tempZjb, 2) - 1.7989 * Math.pow(tempZjb, 3);


        break;
    }
    double tempRed1 = 0;
    switch (JieLiuType)
    {
      case 0: //孔板流量计算
        tempRed1 = tempconQvA * returnValue;
        switch (JieLiuType)
        {
          case 0:
            if (tempRed1 < (170 * Math.pow(tempZjb, 2) * tempGj))
            {
              JOptionPane.showMessageDialog(null, "雷诺数超过标准孔板的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
              return returnValue;
            }
            break;
          case 1:
            if (tempZjb >= 0.1 & tempZjb <= 0.56)
            {
              if (tempRed1 < 5000)
              {
                JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
                return returnValue;
              }
            }
            if (tempZjb > 0.56)
            {
              if (tempRed1 < (16000 * Math.pow(tempZjb, 2) * tempGj))
              {
                JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
                return returnValue;
              }
            }
            break;
        }
        break;

      case 1: //标准喷嘴
        tempRed1 = tempconQvA * returnValue;
        if (tempZjb >= 0.3 & tempZjb < 0.44)
        {
          if (tempRed1 < 70000 | tempRed1 > 10000000.0D)
          {
            JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
          }
        }
        if (tempZjb >= 0.44 & tempZjb < 0.8)
        {
          if (tempRed1 < 20000 | tempRed1 > 10000000.0D)
          {
            JOptionPane.showMessageDialog(null, "雷诺数超过标准喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
          }
        }
        break;


      case 2: //长径喷嘴
        tempRed1 = tempconQvA * returnValue;
        if (tempRed1 < 10000.0D | tempRed1 > 10000000.0D)
        {
          JOptionPane.showMessageDialog(null, "雷诺数超过长径喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
        }
        break;
      case 3: //文丘里喷嘴
        tempRed1 = tempconQvA * returnValue;
        if (tempRed1 < 150000.0D | tempRed1 > 2000000.0D)
        {
          JOptionPane.showMessageDialog(null, "雷诺数超过文丘里喷嘴的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
        }
        break;
      case 4: //粗铸收缩段经典文丘里管
        tempRed1 = tempconQvA * returnValue;
        if (tempRed1 < 200000.0D | tempRed1 > 2000000.0D)
        {
          JOptionPane.showMessageDialog(null, "雷诺数超过粗铸收缩段经典文丘里管的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
          return returnValue;
        }
        break;
      case 5: //机械加工收缩段经典文丘里管
        tempRed1 = tempconQvA * returnValue;
        if (tempRed1 < 200000.0D | tempRed1 > 1000000.0D)
        {
          JOptionPane.showMessageDialog(null, "雷诺数超过机械加工收缩段经典文丘里管的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
        }
        break;
      case 6: //粗焊铁板收缩段经典文丘里管
        tempRed1 = tempconQvA * returnValue;
        if (tempRed1 < 200000.0D | tempRed1 > 2000000.0D)
        {
          JOptionPane.showMessageDialog(null, "雷诺数超过粗焊铁板收缩段经典文丘里管的使用范围！停止计算！", "提示", JOptionPane.PLAIN_MESSAGE);
        }
        break;

      //标准孔板
      //ISA1932喷嘴
      //长径喷嘴
      //文丘里喷嘴
      //粗铸收缩段经典文丘里管
      //机械加工收缩段经典文丘里管
      //粗焊铁板收缩段经典文丘里管




    }
    return returnValue;
  }
  //管道 孔板膨胀后尺寸计算
  private double Work_Cd(int tempCaiLiao, double tempWd_C, double tempCD20)
  {
    //孔板和管道材料的膨胀系数 6143标准
    //0 A3、15号钢
    //1 10 号钢
    //2 20 号钢
    //3 45 号钢
    //4 1 Cr13?2Cr13
    //5 Cr17
    //6 12 CrMoV
    //7 10 CrMo910
    //8 Cr6SiMo
    //9 X20CrMoV121
    //10 1 Cr18Ni9Ti
    //11 普通碳钢
    //12 工业用铜
    //13 黄铜
    //14 红铜
    double CaiLiaoPzxs = 0;
    switch (tempCaiLiao)
    {
      case 0:
        CaiLiaoPzxs = 11.75F;

        CaiLiaoPzxs = 11.6F;
        break;
      case 2:
        CaiLiaoPzxs = 11.16F;

        CaiLiaoPzxs = 11.59F;
        break;
      case 4:
        CaiLiaoPzxs = 10.5F;

        CaiLiaoPzxs = 10.0F;
        break;
      case 6:
        CaiLiaoPzxs = 10.2F;

        CaiLiaoPzxs = 15.5F;
        break;
      case 8:
        CaiLiaoPzxs = 11.5F;

        CaiLiaoPzxs = 10.8F;
        break;
      case 10:
        CaiLiaoPzxs = 16.6F;

        CaiLiaoPzxs = 11.4F;
        break;
      case 12:
        CaiLiaoPzxs = 16.55F;

        CaiLiaoPzxs = 17.8F;
        break;
      case 14:
        CaiLiaoPzxs = 17.2F;
        break;
    }
    return tempCD20 * (1 + 0.000001 * CaiLiaoPzxs * (tempWd_C - 20));
  }
  //查表计算孔板尖锐度系数bk
  // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#.
  private final double[] BkTable_x = new double[10];
  private final double[] BkTable_Y = new double[10];

  private double BkTable(double temPrk, double tempKj, int tempBkjsff)
  {

    //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#

    if (tempBkjsff == 1)
    {

      double tempRkBiKj = 0;
      tempRkBiKj = temPrk / tempKj;

      // static double[] x = new double[10]; //VBConversions Note: Static variable moved to class level and renamed BkTable_x. Local static variables are not supported in C#.
      // static double[] Y = new double[10]; //VBConversions Note: Static variable moved to class level and renamed BkTable_Y. Local static variables are not supported in C#.
      int i = 0;
        int xIndex = 0;
      //If x(0) = 0 Then
      BkTable_x[0] = 0.0004F;
      BkTable_x[1] = 0.001F;
      BkTable_x[2] = 0.002F;
      BkTable_x[3] = 0.004F;
      BkTable_x[4] = 0.006F;
      BkTable_x[5] = 0.008F;
      BkTable_x[6] = 0.01F;
      BkTable_x[7] = 0.012F;
      BkTable_x[8] = 0.014F;
      BkTable_x[9] = 0.015F;

      BkTable_Y[0] = 1;
      BkTable_Y[1] = 1.005F;
      BkTable_Y[2] = 1.012F;
      BkTable_Y[3] = 1.022F;
      BkTable_Y[4] = 1.032F;
      BkTable_Y[5] = 1.04F;
      BkTable_Y[6] = 1.048F;
      BkTable_Y[7] = 1.055F;
      BkTable_Y[8] = 1.062F;
      BkTable_Y[9] = 1.065F;
      //End If

      if (tempRkBiKj <= 0.0004)
      {
        return 1;

      }
      if (tempRkBiKj > 0.015)
      {
        return 1.065F;

      }

      for (i = 0; i <= 8; i++)
      {
        if (tempRkBiKj >= BkTable_x[i] && tempRkBiKj <= BkTable_x[i + 1])
        {
          xIndex = i;
          break;
        }
      }
      return BkTable_Y[xIndex] + (tempRkBiKj - BkTable_x[xIndex]) * (BkTable_Y[xIndex + 1] - BkTable_Y[xIndex]) / (BkTable_x[xIndex + 1] - BkTable_x[xIndex]);
    }
    return 0;
  }
  //管道粗糙度计算
  private double CcdXsjs(double tempPipeType, double tempGj, double tempZjb, double TempRed)
  {
    double returnValue = 0;
    //粗糙度系数计算
    double Jdccd = 0; //绝对粗糙度
    double Xdccd = 0; //相对粗糙度
    //Dim CcdXs As single
    double s1 = 0;
    double s2 = 0;
    double ky = 0;
    double kx = 0;
    int i = 0;
      int m = 0;
      int n = 0;
    if (tempPipeType == 0)
    {
      Jdccd = 0.029F;

      Jdccd = 0.075F;
    }
    else if (tempPipeType == 2)
    {
      Jdccd = 0.075F;

      Jdccd = 0.075F;
    }
    else if (tempPipeType == 4)
    {
      Jdccd = 0.1F;

      Jdccd = 0.15F;
    }
    else if (tempPipeType == 6)
    {
      Jdccd = 1;

      Jdccd = 2.1F;
    }
    else if (tempPipeType == 8)
    {
      Jdccd = 0.04F;

      Jdccd = 0.15F;
    }
    else if (tempPipeType == 10)
    {
      Jdccd = 0.13F;

      Jdccd = 0.25F;
    }
    Xdccd = tempGj / Jdccd;
    if (Xdccd < 400)
    {
      JOptionPane.showMessageDialog(null, "粗糙度取得太高,粗略计算", "提示", JOptionPane.PLAIN_MESSAGE);
      Xdccd = 400;
    }
    if (Xdccd >= 3400)
    {
      Xdccd = 3400;
    }

    if (Xdccd < 3200 & Math.pow(tempZjb, 2) > 0.1 & Math.pow(tempZjb, 2) < 0.64)
    {

      int[] Xdccdb = new int[10];
      double[] Btf = new double[8];
      double[][] CcdXsb = new double[10][8];

      Xdccdb[0] = 400;
      Xdccdb[1] = 800;
      Xdccdb[2] = 1200;
      Xdccdb[3] = 1600;
      Xdccdb[4] = 2000;
      Xdccdb[5] = 2400;
      Xdccdb[6] = 2800;
      Xdccdb[7] = 3200;
      Xdccdb[8] = 3400;

      Btf[0] = 0.1F;
      Btf[1] = 0.2F;
      Btf[2] = 0.3F;
      Btf[3] = 0.4F;
      Btf[4] = 0.5F;
      Btf[5] = 0.6F;
      Btf[6] = 0.64F;

      CcdXsb[0][0] = 1.002;
      CcdXsb[1][0] = 1;
      CcdXsb[2][0] = 1;
      CcdXsb[3][0] = 1;
      CcdXsb[4][0] = 1;
      CcdXsb[5][0] = 1;
      CcdXsb[6][0] = 1;
      CcdXsb[7][0] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][1] = 1.003;
      CcdXsb[1][1] = 1.002;
      CcdXsb[2][1] = 1.001;
      CcdXsb[3][1] = 1;
      CcdXsb[4][1] = 1;
      CcdXsb[5][1] = 1;
      CcdXsb[6][1] = 1;
      CcdXsb[7][1] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][2] = 1.006;
      CcdXsb[1][2] = 1.004;
      CcdXsb[2][2] = 1.002;
      CcdXsb[3][2] = 1.001;
      CcdXsb[4][2] = 1;
      CcdXsb[5][2] = 1;
      CcdXsb[6][2] = 1;
      CcdXsb[7][2] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][3] = 1.009;
      CcdXsb[1][3] = 1.006;
      CcdXsb[2][3] = 1.004;
      CcdXsb[3][3] = 1.002;
      CcdXsb[4][3] = 1.001;
      CcdXsb[5][3] = 1;
      CcdXsb[6][3] = 1;
      CcdXsb[7][3] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][4] = 1.014;
      CcdXsb[1][4] = 1.009;
      CcdXsb[2][4] = 1.006;
      CcdXsb[3][4] = 1.004;
      CcdXsb[4][4] = 1.002;
      CcdXsb[5][4] = 1.001;
      CcdXsb[6][4] = 1;
      CcdXsb[7][4] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][5] = 1.02;
      CcdXsb[1][5] = 1.013;
      CcdXsb[2][5] = 1.009;
      CcdXsb[3][5] = 1.006;
      CcdXsb[4][5] = 1.003;
      CcdXsb[5][5] = 1.002;
      CcdXsb[6][5] = 1;
      CcdXsb[7][5] = 1;
      CcdXsb[8][0] = 1;
      CcdXsb[0][6] = 1.024;
      CcdXsb[1][6] = 1.016;
      CcdXsb[2][6] = 1.011;
      CcdXsb[3][6] = 1.007;
      CcdXsb[4][6] = 1.004;
      CcdXsb[5][6] = 1.002;
      CcdXsb[6][6] = 1.002;
      CcdXsb[7][6] = 1;
      CcdXsb[8][0] = 1;

      for (i = 0; i <= 8; i++)
      {
        if (Xdccd >= Xdccdb[i] && Xdccd <= Xdccdb[i + 1])
        {
          m = i;
          break;
        }
      }
      for (i = 0; i <= 6; i++)
      {
        if (Math.pow(tempZjb, 2) >= Btf[i] && Math.pow(tempZjb, 2) <= Btf[i + 1])
        {
          n = i;
          break;
        }
      }

      ky = (Btf[n + 1] - Btf[n] != 0) ? ((Math.pow(tempZjb, 2) - Btf[n]) / (Btf[n + 1] - Btf[n])) : 0;

      kx = (Xdccdb[m + 1] - Xdccdb[m] != 0) ? ((Xdccd - Xdccdb[m]) / (Xdccdb[m + 1] - Xdccdb[m])) : 0;

      s1 = CcdXsb[m][n] + (CcdXsb[m][n + 1] - CcdXsb[m][n]) * ky;
      s2 = CcdXsb[m + 1][n] + (CcdXsb[m + 1][n + 1] - CcdXsb[m + 1][n]) * ky;
      returnValue = s1 + (s2 - s1) * kx;

      returnValue = TempRed > 1000000.0 ? returnValue : ((returnValue - 1) * Math.pow((Math.log10(TempRed) / 2), 2) + 1);

    }
    else
    {
      returnValue = 1;
    }
    return returnValue;
  }
  //流量换算 工况 标况转寰
  public final double LiuLiang_Zhuanghuan(double tempQ, double tempP_jy_MPa, double tempT_Kai, double tempZn, double tempZ, int ZhuanHuanFangXiang, double tempPn, double tempTn)
  {
    //流量转换


    double temp = 0;


    //double tempPn = 0;
    //double tempTn = 0;
    //switch (tempCbtj)
    //{
    //  case 0:
    //    tempPn = (double) (0.101325F);
    //    tempTn = (double) (293.15F);
    //    break;
    //  case 1:
    //    tempPn = (double) (0.101325F);
    //    tempTn = (double) (288.15F);
    //    break;
    //  case 2:
    //    tempPn = (double) (0.101325F);
    //    tempTn = (double) (273.15F);
    //    break;
    //  case 3:
    //    tempPn = (double) (0.10155981F);
    //    tempTn = (double) (288.7055555F);
    //    break;
    //    //  Case 4
    //    //    LlCs6143.Qn = LlCs6143.Qn * tempLiuChuXiShubT * 0.101325 * llcs6143.ZnZdy / (293.15 * tempLiuChuXiShubP * llcs6143.Zn)
    //}

    switch (ZhuanHuanFangXiang)
    {
      case 0: //工况转标况
        temp = tempQ * (tempP_jy_MPa * tempTn * tempZn) / (tempPn * tempT_Kai * tempZ);
        break;
      case 1:
        temp = tempQ * (tempPn * tempT_Kai * tempZ) / (tempP_jy_MPa * tempTn * tempZn);
        break;
    }
    return temp;
  }
  //计算等熵指数
  public final double Dszs(RefObject<Double> Pjy, RefObject<Double> T, RefObject<Integer> PU, RefObject<Integer> TU)
  {
    return Cpjs(Pjy, T, PU.argValue, TU.argValue) / Cvjs(Pjy, T, PU.argValue, TU.argValue);
  }
  //查表计算甲烷的定压比热Cv
  // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#.
  private final double[][] Cvjs_Cv_Data = new double[8][11];
  private final double[] Cvjs_Cv_T = new double[8];
  private final double[] Cvjs_Cv_P = new double[11];

  public final double Cvjs(RefObject<Double> tempP_jy, RefObject<Double> tempT, int PU, int TU)
  {
    // static double[,] Cv_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_Data. Local static variables are not supported in C#.
    // static double[] Cv_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_T. Local static variables are not supported in C#.
    // static double[] Cv_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Cvjs_Cv_P. Local static variables are not supported in C#.
    double s1 = 0;
    double s2 = 0;
    double ky = 0;
    double kx = 0;
    int i = 0;
    int m = 0;
    int n = 0;
    //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
    Cvjs_Cv_T[0] = -20 + 273.15;
    Cvjs_Cv_T[1] = -10 + 273.15;
    Cvjs_Cv_T[2] = 0 + 273.15;
    Cvjs_Cv_T[3] = 10 + 273.15;
    Cvjs_Cv_T[4] = 20 + 273.15;
    Cvjs_Cv_T[5] = 30 + 273.15;
    Cvjs_Cv_T[6] = 40 + 273.15;
    Cvjs_Cv_T[7] = 50 + 273.15;

    Cvjs_Cv_P[0] = 0.1F;
    Cvjs_Cv_P[1] = 1;
    Cvjs_Cv_P[2] = 2;
    Cvjs_Cv_P[3] = 3;
    Cvjs_Cv_P[4] = 4;
    Cvjs_Cv_P[5] = 5;
    Cvjs_Cv_P[6] = 6;
    Cvjs_Cv_P[7] = 7;
    Cvjs_Cv_P[8] = 8;
    Cvjs_Cv_P[9] = 9;
    Cvjs_Cv_P[10] = 10;
    Cvjs_Cv_Data[0][0] = 1.537;
    Cvjs_Cv_Data[1][0] = 1.583;
    Cvjs_Cv_Data[2][0] = 1.624;
    Cvjs_Cv_Data[3][0] = 1.666;
    Cvjs_Cv_Data[4][0] = 1.704;
    Cvjs_Cv_Data[5][0] = 1.746;
    Cvjs_Cv_Data[6][0] = 1.788;
    Cvjs_Cv_Data[7][0] = 1.825;
    Cvjs_Cv_Data[0][1] = 1.5491;
    Cvjs_Cv_Data[1][1] = 1.5951;
    Cvjs_Cv_Data[2][1] = 1.641;
    Cvjs_Cv_Data[3][1] = 1.683;
    Cvjs_Cv_Data[4][1] = 1.725;
    Cvjs_Cv_Data[5][1] = 1.771;
    Cvjs_Cv_Data[6][1] = 1.804;
    Cvjs_Cv_Data[7][1] = 1.842;
    Cvjs_Cv_Data[0][2] = 1.5492;
    Cvjs_Cv_Data[1][2] = 1.5952;
    Cvjs_Cv_Data[2][2] = 1.649;
    Cvjs_Cv_Data[3][2] = 1.695;
    Cvjs_Cv_Data[4][2] = 1.745;
    Cvjs_Cv_Data[5][2] = 1.787;
    Cvjs_Cv_Data[6][2] = 1.825;
    Cvjs_Cv_Data[7][2] = 1.859;
    Cvjs_Cv_Data[0][3] = 1.5493;
    Cvjs_Cv_Data[1][3] = 1.599;
    Cvjs_Cv_Data[2][3] = 1.6621;
    Cvjs_Cv_Data[3][3] = 1.712;
    Cvjs_Cv_Data[4][3] = 1.766;
    Cvjs_Cv_Data[5][3] = 1.808;
    Cvjs_Cv_Data[6][3] = 1.842;
    Cvjs_Cv_Data[7][3] = 1.871;
    Cvjs_Cv_Data[0][4] = 1.581;
    Cvjs_Cv_Data[1][4] = 1.623;
    Cvjs_Cv_Data[2][4] = 1.6622;
    Cvjs_Cv_Data[3][4] = 1.716;
    Cvjs_Cv_Data[4][4] = 1.775;
    Cvjs_Cv_Data[5][4] = 1.817;
    Cvjs_Cv_Data[6][4] = 1.854;
    Cvjs_Cv_Data[7][4] = 1.887;
    Cvjs_Cv_Data[0][5] = 1.614;
    Cvjs_Cv_Data[1][5] = 1.632;
    Cvjs_Cv_Data[2][5] = 1.678;
    Cvjs_Cv_Data[3][5] = 1.732;
    Cvjs_Cv_Data[4][5] = 1.783;
    Cvjs_Cv_Data[5][5] = 1.821;
    Cvjs_Cv_Data[6][5] = 1.859;
    Cvjs_Cv_Data[7][5] = 1.892;
    Cvjs_Cv_Data[0][6] = 1.616;
    Cvjs_Cv_Data[1][6] = 1.644;
    Cvjs_Cv_Data[2][6] = 1.687;
    Cvjs_Cv_Data[3][6] = 1.753;
    Cvjs_Cv_Data[4][6] = 1.803;
    Cvjs_Cv_Data[5][6] = 1.841;
    Cvjs_Cv_Data[6][6] = 1.871;
    Cvjs_Cv_Data[7][6] = 1.9;
    Cvjs_Cv_Data[0][7] = 1.769;
    Cvjs_Cv_Data[1][7] = 1.645;
    Cvjs_Cv_Data[2][7] = 1.672;
    Cvjs_Cv_Data[3][7] = 1.735;
    Cvjs_Cv_Data[4][7] = 1.785;
    Cvjs_Cv_Data[5][7] = 1.831;
    Cvjs_Cv_Data[6][7] = 1.864;
    Cvjs_Cv_Data[7][7] = 1.901;
    Cvjs_Cv_Data[0][8] = 1.746;
    Cvjs_Cv_Data[1][8] = 1.619;
    Cvjs_Cv_Data[2][8] = 1.648;
    Cvjs_Cv_Data[3][8] = 1.722;
    Cvjs_Cv_Data[4][8] = 1.784;
    Cvjs_Cv_Data[5][8] = 1.833;
    Cvjs_Cv_Data[6][8] = 1.871;
    Cvjs_Cv_Data[7][8] = 1.905;
    Cvjs_Cv_Data[0][9] = 1.708;
    Cvjs_Cv_Data[1][9] = 1.549;
    Cvjs_Cv_Data[2][9] = 1.627;
    Cvjs_Cv_Data[3][9] = 1.71;
    Cvjs_Cv_Data[4][9] = 1.78;
    Cvjs_Cv_Data[5][9] = 1.834;
    Cvjs_Cv_Data[6][9] = 1.875;
    Cvjs_Cv_Data[7][9] = 1.912;
    Cvjs_Cv_Data[0][10] = 1.767;
    Cvjs_Cv_Data[1][10] = 1.566;
    Cvjs_Cv_Data[2][10] = 1.603;
    Cvjs_Cv_Data[3][10] = 1.697;
    Cvjs_Cv_Data[4][10] = 1.779;
    Cvjs_Cv_Data[5][10] = 1.837;
    Cvjs_Cv_Data[6][10] = 1.883;
    Cvjs_Cv_Data[7][10] = 1.917;

    if (tempT.argValue < Cvjs_Cv_T[0])
    {
      tempT.argValue = Cvjs_Cv_T[0];
    }
    if (tempT.argValue > Cvjs_Cv_T[7])
    {
      tempT.argValue = Cvjs_Cv_T[7];
    }
    if (tempP_jy.argValue < Cvjs_Cv_P[0])
    {
      tempP_jy.argValue = Cvjs_Cv_P[0];
    }
    if (tempP_jy.argValue > Cvjs_Cv_P[10])
    {
      tempP_jy.argValue = Cvjs_Cv_P[10];
    }

    for (i = 0; i <= 6; i++)
    {
      if (tempT.argValue >= Cvjs_Cv_T[i] && tempT.argValue <= Cvjs_Cv_T[i + 1])
      {
        m = i;
        break;
      }
    }

    for (i = 0; i <= 9; i++)
    {
      if (tempP_jy.argValue >= Cvjs_Cv_P[i] && tempP_jy.argValue <= Cvjs_Cv_P[i + 1])
      {
        n = i;
        break;
      }
    }

    if (Cvjs_Cv_P[n + 1] - Cvjs_Cv_P[n] != 0)
    {
      ky = (tempP_jy.argValue - Cvjs_Cv_P[n]) / (Cvjs_Cv_P[n + 1] - Cvjs_Cv_P[n]);
    }
    else
    {
      ky = 0;
    }
    if (Cvjs_Cv_T[m + 1] - Cvjs_Cv_T[m] != 0)
    {
      kx = (tempT.argValue - Cvjs_Cv_T[m]) / (Cvjs_Cv_T[m + 1] - Cvjs_Cv_T[m]);
    }
    else
    {
      kx = 0;
    }
    s1 = Cvjs_Cv_Data[m][n] + (Cvjs_Cv_Data[m][n + 1] - Cvjs_Cv_Data[m][n]) * ky;
    s2 = Cvjs_Cv_Data[m + 1][n] + (Cvjs_Cv_Data[m + 1][n + 1] - Cvjs_Cv_Data[m + 1][n]) * ky;
    return s1 + (s2 - s1) * kx;
  }
  //查表计算甲烷的定压比热Cp
  // VBConversions Note: Former VB static variables moved to class level because they aren't supported in C#.
  private final double[][] Cpjs_Cp_Data = new double[8][11];
  private final double[] Cpjs_Cp_T = new double[8];
  private final double[] Cpjs_Cp_P = new double[11];

  public final double Cpjs(RefObject<Double> tempP_jy, RefObject<Double> tempT, int PU, int TU)
  {

    // static double[,] Cp_Data = new double[8, 11]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_Data. Local static variables are not supported in C#.
    // static double[] Cp_T = new double[8]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_T. Local static variables are not supported in C#.
    // static double[] Cp_P = new double[11]; //VBConversions Note: Static variable moved to class level and renamed Cpjs_Cp_P. Local static variables are not supported in C#.
    double Cp1 = 0;
    double Cp2 = 0;
    double ky = 0;
    double kx = 0;
    int i = 0;
    int m = 0;
    int n = 0;
    //On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
    Cpjs_Cp_T[0] = -20 + 273.15;
    Cpjs_Cp_T[1] = -10 + 273.15;
    Cpjs_Cp_T[2] = 0 + 273.15;
    Cpjs_Cp_T[3] = 10 + 273.15;
    Cpjs_Cp_T[4] = 20 + 273.15;
    Cpjs_Cp_T[5] = 30 + 273.15;
    Cpjs_Cp_T[6] = 40 + 273.15;
    Cpjs_Cp_T[7] = 50 + 273.15;

    Cpjs_Cp_P[0] = 0.1F;
    Cpjs_Cp_P[1] = 1;
    Cpjs_Cp_P[2] = 2;
    Cpjs_Cp_P[3] = 3;
    Cpjs_Cp_P[4] = 4;
    Cpjs_Cp_P[5] = 5;
    Cpjs_Cp_P[6] = 6;
    Cpjs_Cp_P[7] = 7;
    Cpjs_Cp_P[8] = 8;
    Cpjs_Cp_P[9] = 9;
    Cpjs_Cp_P[10] = 10;
    Cpjs_Cp_Data[0][0] = 2.064;
    Cpjs_Cp_Data[1][0] = 2.11;
    Cpjs_Cp_Data[2][0] = 2.152;
    Cpjs_Cp_Data[3][0] = 2.194;
    Cpjs_Cp_Data[4][0] = 2.231;
    Cpjs_Cp_Data[5][0] = 2.273;
    Cpjs_Cp_Data[6][0] = 2.315;
    Cpjs_Cp_Data[7][0] = 2.357;
    Cpjs_Cp_Data[0][1] = 2.147;
    Cpjs_Cp_Data[1][1] = 2.184;
    Cpjs_Cp_Data[2][1] = 2.222;
    Cpjs_Cp_Data[3][1] = 2.26;
    Cpjs_Cp_Data[4][1] = 2.298;
    Cpjs_Cp_Data[5][1] = 2.335;
    Cpjs_Cp_Data[6][1] = 2.369;
    Cpjs_Cp_Data[7][1] = 2.403;
    Cpjs_Cp_Data[0][2] = 2.242;
    Cpjs_Cp_Data[1][2] = 2.267;
    Cpjs_Cp_Data[2][2] = 2.305;
    Cpjs_Cp_Data[3][2] = 2.338;
    Cpjs_Cp_Data[4][2] = 2.376;
    Cpjs_Cp_Data[5][2] = 2.406;
    Cpjs_Cp_Data[6][2] = 2.435;
    Cpjs_Cp_Data[7][2] = 2.46;
    Cpjs_Cp_Data[0][3] = 2.357;
    Cpjs_Cp_Data[1][3] = 2.366;
    Cpjs_Cp_Data[2][3] = 2.391;
    Cpjs_Cp_Data[3][3] = 2.421;
    Cpjs_Cp_Data[4][3] = 2.455;
    Cpjs_Cp_Data[5][3] = 2.48;
    Cpjs_Cp_Data[6][3] = 2.501;
    Cpjs_Cp_Data[7][3] = 2.518;
    Cpjs_Cp_Data[0][4] = 2.492;
    Cpjs_Cp_Data[1][4] = 2.481;
    Cpjs_Cp_Data[2][4] = 2.486;
    Cpjs_Cp_Data[3][4] = 2.507;
    Cpjs_Cp_Data[4][4] = 2.533;
    Cpjs_Cp_Data[5][4] = 2.55;
    Cpjs_Cp_Data[6][4] = 2.563;
    Cpjs_Cp_Data[7][4] = 2.576;
    Cpjs_Cp_Data[0][5] = 2.664;
    Cpjs_Cp_Data[1][5] = 2.604;
    Cpjs_Cp_Data[2][5] = 2.593;
    Cpjs_Cp_Data[3][5] = 2.606;
    Cpjs_Cp_Data[4][5] = 2.615;
    Cpjs_Cp_Data[5][5] = 2.624;
    Cpjs_Cp_Data[6][5] = 2.629;
    Cpjs_Cp_Data[7][5] = 2.638;
    Cpjs_Cp_Data[0][6] = 2.868;
    Cpjs_Cp_Data[1][6] = 2.728;
    Cpjs_Cp_Data[2][6] = 2.696;
    Cpjs_Cp_Data[3][6] = 2.696;
    Cpjs_Cp_Data[4][6] = 2.696;
    Cpjs_Cp_Data[5][6] = 2.695;
    Cpjs_Cp_Data[6][6] = 2.694;
    Cpjs_Cp_Data[7][6] = 2.692;
    Cpjs_Cp_Data[0][7] = 3.311;
    Cpjs_Cp_Data[1][7] = 3.001;
    Cpjs_Cp_Data[2][7] = 2.906;
    Cpjs_Cp_Data[3][7] = 2.872;
    Cpjs_Cp_Data[4][7] = 2.849;
    Cpjs_Cp_Data[5][7] = 2.834;
    Cpjs_Cp_Data[6][7] = 2.814;
    Cpjs_Cp_Data[7][7] = 2.803;
    Cpjs_Cp_Data[0][8] = 3.485;
    Cpjs_Cp_Data[1][8] = 3.128;
    Cpjs_Cp_Data[2][8] = 3.005;
    Cpjs_Cp_Data[3][8] = 2.956;
    Cpjs_Cp_Data[4][8] = 2.924;
    Cpjs_Cp_Data[5][8] = 2.9;
    Cpjs_Cp_Data[6][8] = 2.875;
    Cpjs_Cp_Data[7][8] = 2.859;
    Cpjs_Cp_Data[0][9] = 3.633;
    Cpjs_Cp_Data[1][9] = 3.236;
    Cpjs_Cp_Data[2][9] = 3.092;
    Cpjs_Cp_Data[3][9] = 3.034;
    Cpjs_Cp_Data[4][9] = 2.994;
    Cpjs_Cp_Data[5][9] = 2.954;
    Cpjs_Cp_Data[6][9] = 2.932;
    Cpjs_Cp_Data[7][9] = 2.904;
    Cpjs_Cp_Data[0][10] = 3.778;
    Cpjs_Cp_Data[1][10] = 3.347;
    Cpjs_Cp_Data[2][10] = 3.179;
    Cpjs_Cp_Data[3][10] = 3.109;
    Cpjs_Cp_Data[4][10] = 3.06;
    Cpjs_Cp_Data[5][10] = 3.018;
    Cpjs_Cp_Data[6][10] = 2.986;
    Cpjs_Cp_Data[7][10] = 2.953;

    if (tempT.argValue < Cpjs_Cp_T[0])
    {
      tempT.argValue = Cpjs_Cp_T[0];
    }
    if (tempT.argValue > Cpjs_Cp_T[7])
    {
      tempT.argValue = Cpjs_Cp_T[7];
    }
    if (tempP_jy.argValue < Cpjs_Cp_P[0])
    {
      tempP_jy.argValue = Cpjs_Cp_P[0];
    }
    if (tempP_jy.argValue > Cpjs_Cp_P[10])
    {
      tempP_jy.argValue = Cpjs_Cp_P[10];
    }
    for (i = 0; i <= 6; i++)
    {
      if (tempT.argValue >= Cpjs_Cp_T[i] && tempT.argValue <= Cpjs_Cp_T[i + 1])
      {
        m = i;
        break;
      }
    }
    for (i = 0; i <= 9; i++)
    {
      if (tempP_jy.argValue >= Cpjs_Cp_P[i] && tempP_jy.argValue <= Cpjs_Cp_P[i + 1])
      {
        n = i;
        break;
      }
    }
    if (Cpjs_Cp_P[n + 1] - Cpjs_Cp_P[n] != 0)
    {
      ky = (tempP_jy.argValue - Cpjs_Cp_P[n]) / (Cpjs_Cp_P[n + 1] - Cpjs_Cp_P[n]);
    }
    else
    {
      ky = 0;
    }
    if (Cpjs_Cp_T[m + 1] - Cpjs_Cp_T[m] != 0)
    {
      kx = (tempT.argValue - Cpjs_Cp_T[m]) / (Cpjs_Cp_T[m + 1] - Cpjs_Cp_T[m]);
    }
    else
    {
      kx = 0;
    }
    Cp1 = Cpjs_Cp_Data[m][n] + (Cpjs_Cp_Data[m][n + 1] - Cpjs_Cp_Data[m][n]) * ky;
    Cp2 = Cpjs_Cp_Data[m + 1][n] + (Cpjs_Cp_Data[m + 1][n + 1] - Cpjs_Cp_Data[m + 1][n]) * ky;
    return Cp1 + (Cp2 - Cp1) * kx;
  }

}