package com.ng.ngtools.Tools;

import com.ng.ngtools.common.Result;
import com.ng.ngtools.modules.FlowCal;
import com.ng.ngtools.modules.UnitConvert;
import com.ng.ngtools.tangible.RefObject;
import org.springframework.web.bind.annotation.*;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import static javax.xml.bind.DatatypeConverter.parseDouble;
import static javax.xml.bind.DatatypeConverter.parseString;

@RestController
public  class  NG_Cal {

    @ResponseBody
    @GetMapping (value="testCal")
    public Result<String> testCal(@RequestParam(name="par" ) String  par) {

        return Result.ok(par);
    }

    @ResponseBody
    @GetMapping (value="KBFlowcal")
    public Result<String> KBFlowcal(@RequestParam(name="par" ) String [] par)
    {
        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();
        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();


        flPar.dMeterType = (int)tempPar[0]; //流量计类别
        flPar.dCoreType = (int)tempPar[1]; //节流装置类型
        flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准
        flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准
        flPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        flPar.dPb_M = tempPar[5]; //计量参比条件压力
        flPar.dTb_M = tempPar[6]; //计量参比条件温度
        flPar.dPb_E = tempPar[7]; //燃烧参比条件压力
        flPar.dTb_E = tempPar[8]; //燃烧参比条件温度
        flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位
        flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4);
        //当地大气压
        flPar.dNG_Compents = gasPar.adMixture; //天然气组分
        flPar.dPtmode = (int)tempPar[12]; //取压方式
        flPar.dPipeType = (int)tempPar[13]; //管道类型
        flPar.dPipeD = tempPar[14]; //管道内径
        flPar.dLenUnit = (int)tempPar[15]; //长度单位
        flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度
        flPar.dPileDtempUint = (int)tempPar[17]; //温度单位
        flPar.dPipeMaterial = tempPar[18]; //管道材料
        flPar.dOrificeD = tempPar[19]; //孔板孔径
        flPar.dOrificeUnit = (int)tempPar[20]; //长度单位
        flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度
        flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位
        flPar.dOrificeMaterial = tempPar[23]; //孔板材料
        flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法
        flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径
        flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位
        flPar.dPfUnit = (int)tempPar[28]; //压力单位
        flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力
        flPar.dPfType = (int)tempPar[29]; //压力类型
        flPar.dTfUnit = (int)tempPar[31]; //温度单位
        flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度
        flPar.dDpUnit = (int)tempPar[33]; //压力单位
        flPar.dDp = MyConvert.Converter("yl", tempPar[32], flPar.dDpUnit, 0, 4); //输入压力;    //输入差压
        flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位
        flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位
        flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位

        //将压力换算为绝压
        if (flPar.dPfType == 0)
        {
            flPar.dPf = flPar.dPf + flPar.dPatm;
        }

        gasPar.dCbtj = flPar.dCbtj;
        gasPar.dPf = flPar.dPf;
        gasPar.dTf = flPar.dTf;

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Crit(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar2 = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        RefObject<com.ng.ngtools.modules.NG_Cal.FlowParStruct> tempRef_flPar = new RefObject<com.ng.ngtools.modules.NG_Cal.FlowParStruct>(flPar);
        NGFLOW.OFlowCal(tempRef_gasPar2, tempRef_flPar);
        flPar = tempRef_flPar.argValue;
        gasPar = tempRef_gasPar2.argValue;


        tempPar[45] = flPar.dCd;
        tempPar[46] = flPar.dE;
        tempPar[47] = flPar.dFG;
        tempPar[48] = flPar.dFT;
        tempPar[49] = flPar.dDViscosity;
        tempPar[50] = flPar.dDExpCoefficient;
        tempPar[51] = flPar.dRnPipe;
        tempPar[52] = flPar.dBk;
        tempPar[53] = flPar.dRoughNessPipe;
        tempPar[54] = flPar.dCdCorrect;
        tempPar[55] = 0;
//        tempPar[56] = flPar.dVFlowb * 86400;
//        tempPar[57] = flPar.dVFlowf * 3600;
        tempPar[56] = flPar.dVFlowb ;
        tempPar[57] = flPar.dVFlowf ;
        tempPar[58] = flPar.dMFlowb;
        tempPar[59] = flPar.dEFlowb;
        tempPar[60] = flPar.dVelocityFlow;
        tempPar[61] = flPar.dPressLost;
        tempPar[62] = flPar.dBeta;

        tempPar[63] = gasPar.dMrx;
        tempPar[64] = gasPar.dZb;
        tempPar[65] = gasPar.dZf;
        tempPar[66] = gasPar.dFpv;
        tempPar[67] = gasPar.dDb;
        tempPar[68] = gasPar.dDf;
        tempPar[69] = gasPar.dRhob;
        tempPar[70] = gasPar.dRhof;
        tempPar[71] = gasPar.dRD_Ideal;
        tempPar[72] = gasPar.dRD_Real;
        tempPar[73] = gasPar.dHo;
        tempPar[74] = gasPar.dH;
        tempPar[75] = gasPar.dS;
        tempPar[76] = gasPar.dCpi;
        tempPar[77] = gasPar.dCp;
        tempPar[78] = gasPar.dCv;
        tempPar[79] = gasPar.dk;
        tempPar[80] = gasPar.dKappa;
        tempPar[81] = gasPar.dSOS;
        tempPar[82] = gasPar.dCstar;
        tempPar[83] = gasPar.dHhvMol;
        tempPar[84] = gasPar.dLhvMol;
        tempPar[85] = gasPar.dHhvv;
        tempPar[86] = gasPar.dLhvv;
        tempPar[87] = gasPar.dHhvm;
        tempPar[88] = gasPar.dLhvm;
        tempPar[89] = gasPar.dZb11062;
        tempPar[90] = gasPar.dRhob11062;
        tempPar[91] = gasPar.dRhof11062;
        tempPar[92] = gasPar.dRD_Ideal11062;
        tempPar[93] = gasPar.dRD_Real11062;
        tempPar[94] = gasPar.dWobbeIndex;
        tempPar[95] = gasPar.Pc;
        tempPar[96] = gasPar.TC;
        tempPar[97] = gasPar.Bzsx;
        tempPar[98] = gasPar.Bzxx;
        tempPar[99] = gasPar.TotalC;
        tempPar[100] = gasPar.C2;
        tempPar[101] = gasPar.C2j;
        tempPar[102] = gasPar.C3j;
        tempPar[103] = gasPar.C4j;
        tempPar[104] = gasPar.C5j;
        tempPar[105] = gasPar.C6j;
        tempPar[106] = gasPar.C3C4;

        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(tempPar[i] + ",");
        }
        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();

        return Result.ok(json);

    }

    @ResponseBody
    @GetMapping (value="SDFlowcal")
    public Result<String> SDFlowcal(@RequestParam(name="par" ) String [] par)
    {


        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();
        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();


        flPar.dMeterType = (int)tempPar[0]; //流量计类别
        flPar.dCoreType = (int)tempPar[1]; //节流装置类型
        flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准
        flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准
        flPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        flPar.dPb_M = tempPar[5]; //计量参比条件压力
        flPar.dTb_M = tempPar[6]; //计量参比条件温度
        flPar.dPb_E = tempPar[7]; //燃烧参比条件压力
        flPar.dTb_E = tempPar[8]; //燃烧参比条件温度
        flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位
        flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4);
        //当地大气压
        flPar.dNG_Compents = gasPar.adMixture; //天然气组分
        flPar.dPtmode = (int)tempPar[12]; //取压方式
        flPar.dPipeType = (int)tempPar[13]; //管道类型
        flPar.dPipeD = tempPar[14]; //管道内径
        flPar.dLenUnit = (int)tempPar[15]; //长度单位
        flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度
        flPar.dPileDtempUint = (int)tempPar[17]; //温度单位
        flPar.dPipeMaterial = (int)tempPar[18]; //管道材料
        flPar.dOrificeD = tempPar[19]; //孔板孔径
        flPar.dOrificeUnit = (int)tempPar[20]; //长度单位
        flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度
        flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位
        flPar.dOrificeMaterial = (int)tempPar[23]; //孔板材料
        flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法
        flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径
        flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位
        flPar.dPfUnit = (int)tempPar[28]; //压力单位
        flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力
        flPar.dPfType = (int)tempPar[29]; //压力类型
        flPar.dTfUnit = (int)tempPar[31]; //温度单位
        flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度
        flPar.dMeterFactor = (int)tempPar[37]; //仪表系数
        flPar.dPulseNum = tempPar[32]; //脉冲数
        flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位
        flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位
        flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位



        //将压力换算为绝压
        if (flPar.dPfType == 0)
        {
            flPar.dPf = flPar.dPf + flPar.dPatm;
        }

        gasPar.dCbtj = flPar.dCbtj;
        gasPar.dPf = flPar.dPf;
        gasPar.dTf = flPar.dTf;

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Crit(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar2 = new RefObject< com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        RefObject< com.ng.ngtools.modules.NG_Cal.FlowParStruct> tempRef_flPar = new RefObject< com.ng.ngtools.modules.NG_Cal.FlowParStruct>(flPar);
        NGFLOW.SdFlowCal(tempRef_gasPar2, tempRef_flPar);
        flPar = tempRef_flPar.argValue;
        gasPar = tempRef_gasPar2.argValue;

        tempPar[56] = flPar.dVFlowb ;
        tempPar[57] = flPar.dVFlowf ;

//        tempPar[56] = flPar.dVFlowb * 86400;
//        tempPar[57] = flPar.dVFlowf * 3600;
        tempPar[58] = flPar.dMFlowb;
        tempPar[59] = flPar.dEFlowb;
        tempPar[64] = gasPar.dZb;
        tempPar[65] = gasPar.dZf;


        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(tempPar[i] + ",");
        }
        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);

    }

    @ResponseBody
    @GetMapping (value="PZFlowcal")
    public Result<String> PZFlowcal(@RequestParam(name="par" ) String [] par) {
        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.FlowParStruct flPar = new com.ng.ngtools.modules.NG_Cal.FlowParStruct();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();
        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();


        flPar.dMeterType = (int)tempPar[0]; //流量计类别
        flPar.dCoreType = (int)tempPar[1]; //节流装置类型
        flPar.dFlowCalbz = (int)tempPar[2]; //流量计算标准
        flPar.dZcalbz = (int)tempPar[3]; //压缩因子计算标准
        flPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        flPar.dPb_M = tempPar[5]; //计量参比条件压力
        flPar.dTb_M = tempPar[6]; //计量参比条件温度
        flPar.dPb_E = tempPar[7]; //燃烧参比条件压力
        flPar.dTb_E = tempPar[8]; //燃烧参比条件温度
        flPar.dPatmUnit = (int)tempPar[10]; //当地大气压单位
        flPar.dPatm = MyConvert.Converter("yl", tempPar[9], flPar.dPatmUnit, 0, 4);
        //当地大气压
        flPar.dNG_Compents = gasPar.adMixture; //天然气组分
        flPar.dPtmode = (int)tempPar[12]; //取压方式
        flPar.dPipeType = (int)tempPar[13]; //管道类型
        flPar.dPipeD = tempPar[14] / 1000; //管道内径
        flPar.dLenUnit = (int)tempPar[15]; //长度单位
        flPar.dPipeDtemp = tempPar[16]; //管道内径参考温度
        flPar.dPileDtempUint = (int)tempPar[17]; //温度单位
        flPar.dPipeMaterial = (int)tempPar[18]; //管道材料
        flPar.dOrificeD = tempPar[19] / 1000; //喷嘴喉径换算成米
        flPar.dOrificeUnit = (int)tempPar[20]; //长度单位
        flPar.dOrificeDtemp = tempPar[21]; //孔板内径参考温度
        flPar.dOrificeDtempUnit = (int)tempPar[22]; //温度单位
        flPar.dOrificeMaterial = (int)tempPar[23]; //孔板材料
        flPar.dOrificeSharpness = (int)tempPar[24]; //锐利度系数计算方法
        flPar.dOrificeRk = tempPar[25]; //孔板入口圆弧半径
        flPar.dOrificeRkLenUint = (int)tempPar[26]; //长度单位
        flPar.dPfUnit = (int)tempPar[28]; //压力单位
        flPar.dPf = MyConvert.Converter("yl", tempPar[27], flPar.dPfUnit, 0, 4); //输入压力
        flPar.dPfType = (int)tempPar[29]; //压力类型
        flPar.dTfUnit = (int)tempPar[31]; //温度单位
        flPar.dTf = MyConvert.Converter("wd", tempPar[30], flPar.dTfUnit, 1, 4); //输入温度
        flPar.dDpUnit = (int)tempPar[33]; //压力单位
        flPar.dDp = MyConvert.Converter("yl", tempPar[32], flPar.dDpUnit, 0, 4); //输入压力;    //输入差压
        flPar.dVFlowUnit = (int)tempPar[34]; //体积流量单位
        flPar.dMFlowUnit = (int)tempPar[35]; //质量流量单位
        flPar.dEFlowUnit = (int)tempPar[36]; //能量流量单位
        flPar.dCd = tempPar[37]; //流出系数


        //将压力换算为绝压
        if (flPar.dPfType == 0)
        {
            flPar.dPf = flPar.dPf + flPar.dPatm;
        }

        gasPar.dCbtj = flPar.dCbtj;
        gasPar.dPf = flPar.dPf;
        gasPar.dTf = flPar.dTf;

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Crit(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

         RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar2 = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
         RefObject<com.ng.ngtools.modules.NG_Cal.FlowParStruct> tempRef_flPar = new RefObject<com.ng.ngtools.modules.NG_Cal.FlowParStruct>(flPar);
        NGFLOW.NozellFLowCal(tempRef_gasPar2, tempRef_flPar);
        flPar = tempRef_flPar.argValue;
        gasPar = tempRef_gasPar2.argValue;

        tempPar[56] = flPar.dVFlowb ;
        tempPar[57] = flPar.dVFlowf;
//        tempPar[56] = flPar.dVFlowb * 86400;
//        tempPar[57] = flPar.dVFlowf * 3600;
        tempPar[58] = flPar.dMFlowb;
        tempPar[59] = flPar.dEFlowb;

        tempPar[64] = gasPar.dZb;
        tempPar[65] = gasPar.dZf;
        tempPar[80] = gasPar.dKappa;
        tempPar[82] = gasPar.dCstar;

        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(tempPar[i] + ",");
        }
        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);
    }

    @ResponseBody
    @GetMapping (value="ParCal")
    private Result<String> ParCal(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();

        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();

        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();

        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件

        int dPfUnit = (int)tempPar[28]; //压力单位
        gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力
        int dPfType = (int)tempPar[29]; //压力类型
        int dTfUnit = (int)tempPar[31]; //温度单位
        gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度

        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压

        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NGCal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NGCal.Crit(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        tempPar[63] = gasPar.dMrx;
        tempPar[64] = gasPar.dZb;
        tempPar[65] = gasPar.dZf;
        tempPar[66] = gasPar.dFpv;
        tempPar[67] = gasPar.dDb;
        tempPar[68] = gasPar.dDf;
        tempPar[69] = gasPar.dRhob;
        tempPar[70] = gasPar.dRhof;
        tempPar[71] = gasPar.dRD_Ideal;
        tempPar[72] = gasPar.dRD_Real;
        tempPar[73] = gasPar.dHo;
        tempPar[74] = gasPar.dH;
        tempPar[75] = gasPar.dS;
        tempPar[76] = gasPar.dCpi;
        tempPar[77] = gasPar.dCp;
        tempPar[78] = gasPar.dCv;
        tempPar[79] = gasPar.dk;
        tempPar[80] = gasPar.dKappa;
        tempPar[81] = gasPar.dSOS;
        tempPar[82] = gasPar.dCstar;
        tempPar[83] = gasPar.dHhvMol;
        tempPar[84] = gasPar.dLhvMol;
        tempPar[85] = gasPar.dHhvv;
        tempPar[86] = gasPar.dLhvv;
        tempPar[87] = gasPar.dHhvm;
        tempPar[88] = gasPar.dLhvm;
        tempPar[89] = gasPar.dZb11062;
        tempPar[90] = gasPar.dRhob11062;
        tempPar[91] = gasPar.dRhof11062;
        tempPar[92] = gasPar.dRD_Ideal11062;
        tempPar[93] = gasPar.dRD_Real11062;
        tempPar[94] = gasPar.dWobbeIndex;
        tempPar[95] = gasPar.Pc;
        tempPar[96] = gasPar.TC;
        tempPar[97] = gasPar.Bzsx;
        tempPar[98] = gasPar.Bzxx;
        tempPar[99] = gasPar.TotalC;
        tempPar[100] = gasPar.C2;
        tempPar[101] = gasPar.C2j;
        tempPar[102] = gasPar.C3j;
        tempPar[103] = gasPar.C4j;
        tempPar[104] = gasPar.C5j;
        tempPar[105] = gasPar.C6j;
        tempPar[106] = gasPar.C3C4;

        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(String.valueOf(tempPar[i]) + ",");
        }

        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);
    }

    @ResponseBody
    @GetMapping (value="GSCVCal")
    private Result<String> GSCVCal(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();

        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();

        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();

        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件

        int dPfUnit = (int)tempPar[28]; //压力单位
        gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力
        int dPfType = (int)tempPar[29]; //压力类型
        int dTfUnit = (int)tempPar[31]; //温度单位
        gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度

        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压

        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Zcal(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        double dV = tempPar[37];
        double dVCNG = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb);

        tempPar[63] = dVCNG;
        tempPar[64] = dVCNG * gasPar.dRhob;



        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(String.valueOf(tempPar[i]) + ",");
        }

        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);
    }
    @ResponseBody
    @GetMapping (value="GSCVTCal")
    private Result<Object> GSCVTCal(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();

        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();

        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        int dPfUnit = (int)tempPar[28]; //压力单位
        int dTfUnit = (int)tempPar[31]; //温度单位
        int dPfType = (int)tempPar[29]; //压力类型
        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压



        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();

        double dPstart = tempPar[27];
        double dTstart = tempPar[30];

        double dV = tempPar[37];

        double dPend = tempPar[40];
        double dTend = tempPar[41];
        double dPjg = tempPar[38];
        double dTjg = tempPar[39];


        int Ccount =Integer.parseInt(String.valueOf(Math.round((dPend - dPstart) / dPjg ))) +1;
        int Rcount = Integer.parseInt( String.valueOf(Math.round((dTend - dTstart) / dTjg))) + 1;

        double[] arrP = new double[Ccount];
        double[] arrT = new double[Rcount];

       String [][] arrGSCV=new String[Rcount+1][Ccount+1];
arrGSCV[0][0]="T-V-P";

        for (int i = 0; i < Ccount; i++)
        {
            arrP[i] = dPstart + i * dPjg;
            arrGSCV[0][i+1]=String.valueOf(arrP[i]) + " MPa";
        }
        for (int i = 0; i < Rcount; i++)
        {
            arrT[i] = dTstart + i * dTjg;
        }

        int totalNum = Ccount * Rcount;
        int jsnum = 0;
        int dbPerJd = 0;


        for (int i = 0; i < Rcount; i++)
        {

            arrGSCV[i+1][0]= arrT[i] + " ℃";

            for (int j = 0; j < Ccount; j++)
            {
                //将压力换算为绝压
                gasPar.dPf = MyConvert.Converter("yl", arrP[j], dPfUnit, 0, 4); //输入压力
                gasPar.dTf = MyConvert.Converter("wd", arrT[i], dTfUnit, 1, 4); //输入温度
                if (dPfType == 0)
                {
                    gasPar.dPf = gasPar.dPf + dPatm;
                }
                RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
                NG_Cal.Zcal(tempRef_gasPar, 0.0);
                gasPar = tempRef_gasPar.argValue;
                DecimalFormat df=new DecimalFormat("0.####");
                arrGSCV[i+1][j+1]= (String.valueOf(df.format(dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb))));
                jsnum += 1;
                dbPerJd = jsnum * 100 / totalNum;
            }
        }

        return Result.ok(arrGSCV);
    }
    @ResponseBody
    @GetMapping (value="ZTCal")
    private Result<Object> ZTCal(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();
        gasPar.adMixture = ngCom;
        UnitConvert MyConvert = new UnitConvert();
        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }
        int dPfUnit = (int)tempPar[28]; //压力单位
        int dTfUnit = (int)tempPar[31]; //温度单位
        int dPfType = (int)tempPar[29]; //压力类型
        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压
        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        double dPstart = tempPar[27];
        double dTstart = tempPar[30];


        double dPend = tempPar[39];
        double dTend = tempPar[40];
        double dPjg = tempPar[37];
        double dTjg = tempPar[38];

        int Ccount =Integer.parseInt(String.valueOf(Math.round((dPend - dPstart) / dPjg ))) +1;
        int Rcount = Integer.parseInt( String.valueOf(Math.round((dTend - dTstart) / dTjg))) + 1;

        double[] arrP = new double[Ccount];
        double[] arrT = new double[Rcount];

        String [][] arrZ=new String[Rcount+1][Ccount+1];

arrZ[0][0]="T_Z_P";

        for (int i = 0; i < Ccount; i++)
        {
            arrP[i] = dPstart + i * dPjg;
           arrZ[0][i+1]= arrP[i] + " MPa";
              }
        for (int i = 0; i < Rcount; i++)
        {
            arrT[i] = dTstart + i * dTjg;
        }

        int totalNum = Ccount * Rcount;
        int jsnum = 0;
        float dbPerJd = 0;
        for (int i = 0; i < Rcount; i++)
        {
            arrZ[i+1][0]= (String.valueOf(arrT[i])) + " ℃";
            for (int j = 0; j < Ccount; j++)
            {
                //将压力换算为绝压
                gasPar.dPf = MyConvert.Converter("yl", arrP[j], dPfUnit, 0, 4); //输入压力
                gasPar.dTf = MyConvert.Converter("wd", arrT[i], dTfUnit, 1, 4); //输入温度
                if (dPfType == 0)
                {
                    gasPar.dPf = gasPar.dPf + dPatm;
                }

                RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
                NG_Cal.Zcal(tempRef_gasPar, 0.0);
                gasPar = tempRef_gasPar.argValue;
                DecimalFormat df=new DecimalFormat("0.####");
                arrZ[i+1][j+1]=  (String.valueOf(df.format( gasPar.dZf)));
                jsnum += 1;
                dbPerJd = jsnum * 100 / totalNum;


            }
        }
        return Result.ok(arrZ);
    }

    @ResponseBody
    @GetMapping (value="ZXCCal")
    private Result<String> ZXCCal(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();

        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();

        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件

        int dPfUnit = (int)tempPar[28]; //压力单位
        int dPfType = (int)tempPar[29]; //压力类型
        int dTfUnit = (int)tempPar[31]; //温度单位
        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压
        gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力
        gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度


        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Zcal(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        double dV = tempPar[37];

        double dVNG = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb);

        //最终压力温度计算
        gasPar.dPf = MyConvert.Converter("yl", tempPar[38], dPfUnit, 0, 4); //输入压力
        gasPar.dTf = MyConvert.Converter("wd", tempPar[39], dTfUnit, 1, 4); //输入温度


        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar2 = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Zcal(tempRef_gasPar2, 0.0);
        gasPar = tempRef_gasPar2.argValue;

        double dVNGe = dV * gasPar.dPf * gasPar.dTb * gasPar.dZb / (gasPar.dTf * gasPar.dZf * gasPar.dPb);


        tempPar[63] = dVNGe - dVNG;
        tempPar[64] = (dVNGe - dVNG) * gasPar.dRhob;



        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(String.valueOf(tempPar[i]) + ",");
        }
        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);
    }

    @ResponseBody
    @GetMapping (value="LNGQhjs")
    private Result<String> LNGQhjs(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        FlowCal NGFLOW = new FlowCal();
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();

        gasPar.adMixture = ngCom;

        UnitConvert MyConvert = new UnitConvert();

        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件

        int dPfUnit = (int)tempPar[28]; //压力单位
        int dPfType = (int)tempPar[29]; //压力类型
        int dTfUnit = (int)tempPar[31]; //温度单位
        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压
        gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力
        gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度


        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Zcal(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        double dMLNG = tempPar[37];
        double dVLNG=dMLNG/gasPar.dRhob;


        tempPar[63] = dVLNG;
        tempPar[69] = gasPar.dRhob;



        StringBuilder Json = new StringBuilder();
        Json.append("[");
        for (int i = 0; i < tempPar.length; i++)
        {
            Json.append(String.valueOf(tempPar[i]) + ",");
        }
        String json = (Json.replace(Json.length() - 1, Json.length(), ",").append("]")).toString();
        return Result.ok(json);
    }



    @ResponseBody
    @GetMapping (value="SQGYjs")
    private Result<String> SQGYjs(String[] par)
    {

        double[] ngCom = new double[21];
        double[] tempPar = new double[110];
        for (int i = 0; i < par.length; i++)
        {
            if (i != 11)
            {
                tempPar[i] = Double.parseDouble(par[i]);
            }
            else
            {
                for (int j = 0; j < 21; j++)
                {
                    ngCom[j] = Double.parseDouble(par[11].split("[_]", -1)[j]) / 100;
                }
            }
        }
        com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT gasPar = new com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT();
        gasPar.adMixture = ngCom;
        UnitConvert MyConvert = new UnitConvert();
        gasPar.dCbtj = (int)tempPar[4]; //'计量参比条件
        int dPfUnit = (int)tempPar[28]; //压力单位
        int dPfType = (int)tempPar[29]; //压力类型
        int dTfUnit = (int)tempPar[31]; //温度单位
        int dPatmUnit = (int)tempPar[10]; //当地大气压单位
        double dPatm = MyConvert.Converter("yl", tempPar[9], dPatmUnit, 0, 4);
        ; //当地大气压
        gasPar.dPf = MyConvert.Converter("yl", tempPar[27], dPfUnit, 0, 4); //输入压力
        gasPar.dTf = MyConvert.Converter("wd", tempPar[30], dTfUnit, 1, 4); //输入温度


        //将压力换算为绝压
        if (dPfType == 0)
        {
            gasPar.dPf = gasPar.dPf + dPatm;
        }

        switch (gasPar.dCbtj)
        {
            case 2:
                gasPar.dPb = 101325;
                gasPar.dTb = 273.15;
                break;
            case 1:
                gasPar.dPb = 101325;
                gasPar.dTb = 288.15;
                break;
            case 0:
                gasPar.dPb = 101325;
                gasPar.dTb = 293.15;
                break;
        }

        com.ng.ngtools.modules.NG_Cal NG_Cal = new com.ng.ngtools.modules.NG_Cal();
        RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT> tempRef_gasPar = new RefObject<com.ng.ngtools.modules.NG_Cal.GasPropsSTRUCT>(gasPar);
        NG_Cal.Zcal(tempRef_gasPar, 0.0);
        gasPar = tempRef_gasPar.argValue;

        double pipleDw=Double.parseDouble(par[40]) ;  //管道外径
        double pipleBh=Double.parseDouble(par[41]) ;  //管道壁厚
        double pipleDn=(pipleDw-2*pipleBh)/10;
        double pipleL=Double.parseDouble(par[42]) ;  //管道长度
        double startP=Double.parseDouble(par[43]) ;  //起点压力
        double endP=Double.parseDouble(par[44]) ;   //终点压力
        double flowSq=Double.parseDouble(par[45]);  //输气量
        String JSGS= par[38];  //计算公式
        double exlxs=XLXS(pipleDw);

        double ZRDTL = gasPar.dZf * gasPar.dRD_Real * gasPar.dTf * pipleL;
        double ZRDTL051 = gasPar.dZf * Math.pow(gasPar.dRD_Real, 0.961) * gasPar.dTf * pipleL;
        double PowZRDTL05 = Math.pow(ZRDTL, 0.5);
        double PowZRDTL051 = Math.pow(ZRDTL051, 0.51);
        double powDn83 = Math.pow(pipleDn, 8 / 3);
        double powDn253 = Math.pow(pipleDn, 2.53);
        double powDn27 = Math.pow(pipleDn, 2.7);
        double powDn26 = Math.pow(pipleDn, 2.6);
        double powPsPe05 = Math.pow((startP * startP - endP * endP), 0.5);
        double powPsPe051 = Math.pow((startP * startP - endP * endP), 0.51);
        double result=0;
        String jsCs=par[37];
        switch (jsCs)
        {
            case "0":   //输气能力
                switch (JSGS) {
                    case "0":  ////10.8432=5033/10^(8/3)
                        result = 5033 * powDn83 * powPsPe05 / PowZRDTL05;
                        break;
                    case "1":  //24.8244=11522/10^(8/3)
                        //alert(Exlxs + "_" + powDn253 + "_" + powPsPe051 + "_" + PowZRDTL051 + "_" + L + "_" + Z + "_" + Dn + "_" + Q);
                        result = 11522 * exlxs * powDn253 * powPsPe051 / PowZRDTL051;
                        break;
                    case "2":  //24.8244=11522/10^(8/3)
                        result = 4464.2 * powDn27 * powPsPe05 / PowZRDTL05;
                        break;
                    case "3":  //24.8244=11522/10^(8/3)
                        result = 6775.6 * exlxs * 1 * powDn26 * powPsPe05 / PowZRDTL05;
                        break;
                    default:
                }
                break;
            case "1":  //管道内径计算

                switch (JSGS) {
                    case "0":  //10.8432=5033/10^(8/3)
                        result = Math.pow(flowSq / (5033 * powPsPe05 / PowZRDTL05), (double) 3 / 8) * 10;  //* Math.pow(Dn, 8 / 3)
                        break;
                    case "1":  //24.8244=11522/10^(8/3)

                        //result = Math.pow(Q / (11522 * powPsPe051 / PowZRDTL051), 1 / 2.53)*10;  //* Math.pow(Dn, 2.53)
                        //Exlxs = XLXS(parseFloat(result));
                        result = Math.pow(flowSq / (11522 * exlxs * powPsPe051 / PowZRDTL051), 1 / 2.53) * 10;  //* Math.pow(Dn, 2.53)

                        break;
                    case "2":  //24.8244=11522/10^(8/3)
                        result = Math.pow(flowSq / (4464.2 * powPsPe05 / PowZRDTL05), 1 / 2.7) * 10; //* Math.pow(Dn, 2.7)
                        break;
                    case "3":  //24.8244=11522/10^(8/3)
                        result = Math.pow(flowSq / (6775.6 * exlxs * 1 * powPsPe05 / PowZRDTL05), 1 / 2.6) * 10; //* Math.pow(Dn, 2.6)
                        break;


                    default:
                }
                break;

            case "2":  //管道长度


                switch (JSGS) {
                    case "0":  //10.8432=5033/10^(8/3)
                        result = Math.pow(5033 * powDn83 * powPsPe05 / PowZRDTL05 / flowSq, 2);
                        break;
                    case "1":  //24.8244=11522/10^(8/3)
                        result = Math.pow(11522 * exlxs * powDn253 * powPsPe051 / PowZRDTL051 / flowSq, 1 / 0.51);
                        break;
                    case "2":  //24.8244=11522/10^(8/3)
                        result = Math.pow(4464.2 * powDn27 * powPsPe05 / PowZRDTL05 / flowSq, 2);
                        break;
                    case "3":  //24.8244=11522/10^(8/3)
                        result = Math.pow(6775.6 * exlxs * 1 * powDn26 * powPsPe05 / PowZRDTL05 / flowSq, 2);
                        break;


                    default:
                }

                break;


            case "3":  //起点压力

                //var powPsPe05 = Math.pow((Ps * Ps - Pe * Pe), 0.5);
                //var powPsPe051 = Math.pow((Ps * Ps - Pe * Pe), 0.51);

                switch (JSGS) {
                    case "0":  //10.8432=5033/10^(8/3)
                        result = Math.sqrt(Math.pow(flowSq / (5033 * powDn83 / PowZRDTL05), 2) + endP * endP);
                        break;
                    case "1":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(Math.pow(flowSq / (11522 * exlxs * powDn253 / PowZRDTL051), 1 / 0.51) + endP * endP);;
                        break;
                    case "2":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(Math.pow(flowSq / (4464.2 * powDn27 / PowZRDTL05), 2) + endP * endP);
                        break;
                    case "3":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(Math.pow(flowSq / (6775.6 * exlxs * 1 * powDn26 / PowZRDTL05), 2) + endP * endP);
                        break;


                    default:
                }

                result = result - 0.101325;

                break;

            case "4":  //终点压力



                switch (JSGS) {
                    case "0":  //10.8432=5033/10^(8/3)
                        result = Math.sqrt(startP * startP - Math.pow(flowSq / (5033 * powDn83 / PowZRDTL05), 2));
                        break;
                    case "1":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(startP * startP - Math.pow(flowSq / (11522 * exlxs * powDn253 / PowZRDTL051), 1 / 0.51));
                        break;
                    case "2":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(startP * startP - Math.pow(flowSq / (4464.2 * powDn27 / PowZRDTL05), 2));
                        break;
                    case "3":  //24.8244=11522/10^(8/3)
                        result = Math.sqrt(startP * startP - Math.pow(flowSq / (6775.6 * exlxs * 1 * powDn26 / PowZRDTL05), 2));
                        break;


                    default:
                }

                result = result - 0.101325;

                break;

            case "5":  //管存量
                double pipleV = 3.1415926 * pipleDn * pipleDn * pipleL * 1000 / 40000;
                //alert(Dn  +"_"+V);
                result = pipleV * ((startP + endP) / 2) * gasPar.dZb * 293.15 / gasPar.dZf / gasPar.dTf / 0.101325;
        }
        return  Result.ok(String.valueOf(result));
    }

    private  double XLXS(double pD){

        //alert(pD);
        if (pD > 0 & pD < 300) {
            return 0.84;
        }
        else if (pD >= 300 & pD < 400) {
            return 0.85;
        }
        else if (pD >= 400 & pD < 500) {
            return 0.84;
        }
        else if (pD >= 500 & pD < 600) {
            return 0.87;
        }
        else if (pD >= 700 & pD < 800) {
            return 0.9;
        }
        else if (pD >= 800 & pD < 1000) {
            return 0.91;
        }
        else {
            return 0.85;
        }




    }

}
