AGA Calculations Library and Source Code

SCADACore provides American Gas Association calculation libraries and full source code to developers needing to calculate gas flow.

Complete C/C++, C#, and Python AGA Calculation Source Code

SCADACore’s AGA Gas Flow Library / Source Code provides verified AGA gas flow calculations specified by the American Gas Association. All available AGA Calculations are combined into one easy-to-use DLL. The source code is also available for use in embedded systems, as well as to assist manufacturers in bringing their flow computers to the market with accurate flow calculations.

  • Verified with AGA Test Cases

  • Trusted and Deployed on Numerous Systems

  • Complete Suite of AGA Calculations

  • Usage Example Project

  • Save Hundreds of Hours of Development and Testing

  • Licensed by Companies Worldwide

  • Full Source Code Files in C/C++, C#, and Python

Contact Us

Code Usage Samples

The AGA 3 Calculation is the most common AGA calculation used for measure natural gas flow through orifice meters and V-Cone. 

Compressibility factors if known can be inputted manually or AGA 8 calculations can be performed to calculate the compressibility based on the gas compositions of the well.

private void AGA3Example()
{
double flowTemperatureInCelcius = 57;
double pipeReferenceTemperatureInCelcius = 20;
double orificeReferenceTemperatureInCelcius = 20;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 2818.09;
double baseStaticPressureKPA = 101.325;
double differentialPressureKPA = 10.2000;
double orificeSizeMM = 9.525;
double pipeSizeMM = 52.370;
AgaConstants.MaterialType orificeMaterial = AgaConstants.MaterialType.StainlessSteel;
AgaConstants.MaterialType pipeMaterial = AgaConstants.MaterialType.CarbonSteel;
bool tapIsUpstream = true;
double flowCompressibility = .9280;
double baseCompressibility = .9959;
double specificGravity = .7792;

AGAFlowCalculation.Aga3 aga3calc = new AGAFlowCalculation.Aga3();

AGA3Result result = aga3calc.CalculateFlow(flowTemperatureInCelcius, pipeReferenceTemperatureInCelcius, orificeReferenceTemperatureInCelcius, baseTemperatureInCelcius, staticPressureKPA, baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM,
orificeMaterial, pipeMaterial, tapIsUpstream,flowCompressibility,baseCompressibility,specificGravity);

System.Console.WriteLine(“AGA3 Test with Flow Compressibility, Base Compressibility, and Specific Gravity Entered”);
System.Console.WriteLine(“Base Compressibility: ” + result.BaseCompressibility_Zb);
System.Console.WriteLine(“Compressibility: ” + result.Compressibility_FPV);
System.Console.WriteLine(“Flowing Compressibility: ” + result.FlowingCompressibility_Zf);
System.Console.WriteLine(“Specific Gravity: ” + result.SpecificGravity);

System.Console.WriteLine(“***Flow***: ” + result.Flow);

System.Console.WriteLine(“Press Enter To Exit”);
System.Console.ReadLine();
}

The AGA 8 Calculations take Gas Compositions as parameters and produce the compressibility factors that can then be used by AGA 3, AGA 7 or AGA 11 to perform more accurate calculations.

private void AGA8Example()
{
//Example of AGA8/AGA3 Flow calculation with Gas Compositions…
AGAFlowCalculation.GasComps gascomps = new AGAFlowCalculation.GasComps();

gascomps.Add(.0184, AGAFlowCalculation.AgaConstants.GasCompositions.Nitrogen_N2);
gascomps.Add(0, AGAFlowCalculation.AgaConstants.GasCompositions.CarbonDioxide_CO2);
gascomps.Add(.0260, AGAFlowCalculation.AgaConstants.GasCompositions.HydrogenSulfide_H2S);
gascomps.Add(.7068, AGAFlowCalculation.AgaConstants.GasCompositions.Methane_C1);
gascomps.Add(.1414, AGAFlowCalculation.AgaConstants.GasCompositions.Ethane_C2);
gascomps.Add(.0674, AGAFlowCalculation.AgaConstants.GasCompositions.Propane_C3);
gascomps.Add(.0081, AGAFlowCalculation.AgaConstants.GasCompositions.iButane_iC4);
gascomps.Add(.0190, AGAFlowCalculation.AgaConstants.GasCompositions.nButane_nC4);
gascomps.Add(.0038, AGAFlowCalculation.AgaConstants.GasCompositions.iPentane_iC5);
gascomps.Add(.0043, AGAFlowCalculation.AgaConstants.GasCompositions.nPentane_nC5);
gascomps.Add(.0026, AGAFlowCalculation.AgaConstants.GasCompositions.nHexane_C6);
gascomps.Add(.0022, AGAFlowCalculation.AgaConstants.GasCompositions.nHeptane_C7);

double flowTemperatureInCelcius = 57;
double pipeReferenceTemperatureInCelcius = 20;
double orificeReferenceTemperatureInCelcius = 20;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 2818.09;
double baseStaticPressureKPA = 101.325;
double differentialPressureKPA = 10.2000;
double orificeSizeMM = 9.525;
double pipeSizeMM = 52.370;
AgaConstants.MaterialType orificeMaterial = AgaConstants.MaterialType.StainlessSteel;
AgaConstants.MaterialType pipeMaterial = AgaConstants.MaterialType.CarbonSteel;
bool tapIsUpstream = true;

AGAFlowCalculation.Aga3 aga3calc = new AGAFlowCalculation.Aga3();

AGA3Result result = aga3calc.CalculateFlow(flowTemperatureInCelcius, pipeReferenceTemperatureInCelcius,
orificeReferenceTemperatureInCelcius, baseTemperatureInCelcius, staticPressureKPA,
baseStaticPressureKPA, differentialPressureKPA, orificeSizeMM, pipeSizeMM,
orificeMaterial, pipeMaterial, tapIsUpstream, gascomps);

System.Console.WriteLine(“AGA3 Test with AGA8 Gas Compositions calculating compressibility and specific gravity”);
System.Console.WriteLine(“Base Compressibility: ” + result.BaseCompressibility_Zb);
System.Console.WriteLine(“Compressibility: ” + result.Compressibility_FPV);
System.Console.WriteLine(“Flowing Compressibility: ” + result.FlowingCompressibility_Zf);
System.Console.WriteLine(“Specific Gravity: ” + result.SpecificGravity);

System.Console.WriteLine(“***Flow***: ” + result.Flow);

System.Console.WriteLine(“Press Enter To Continue”);
System.Console.ReadLine();
}

When performing AGA 7 calculations you can either manually input the compressibility factors or use AGA 8 calculations to calculate the compressibility using the gas compositions.

public void AGA 7 Test()
{
AGAFlowCalculation.GasComps gascomps = new AGAFlowCalculation.GasComps();

gascomps.Add(.0184, AGAFlowCalculation.AgaConstants.GasCompositions.Nitrogen_N2);
gascomps.Add(0, AGAFlowCalculation.AgaConstants.GasCompositions.CarbonDioxide_CO2);
gascomps.Add(.0260, AGAFlowCalculation.AgaConstants.GasCompositions.HydrogenSulfide_H2S);
gascomps.Add(.7068, AGAFlowCalculation.AgaConstants.GasCompositions.Methane_C1);
gascomps.Add(.1414, AGAFlowCalculation.AgaConstants.GasCompositions.Ethane_C2);
gascomps.Add(.0674, AGAFlowCalculation.AgaConstants.GasCompositions.Propane_C3);
gascomps.Add(.0081, AGAFlowCalculation.AgaConstants.GasCompositions.iButane_iC4);
gascomps.Add(.0190, AGAFlowCalculation.AgaConstants.GasCompositions.nButane_nC4);
gascomps.Add(.0038, AGAFlowCalculation.AgaConstants.GasCompositions.iPentane_iC5);
gascomps.Add(.0043, AGAFlowCalculation.AgaConstants.GasCompositions.nPentane_nC5);
gascomps.Add(.0026, AGAFlowCalculation.AgaConstants.GasCompositions.nHexane_C6);
gascomps.Add(.0022, AGAFlowCalculation.AgaConstants.GasCompositions.nHeptane_C7);

double flowTemperatureInCelcius = 45.5;
double meterFactor = 2.0000;
double flowVolume = 10;
double baseTemperatureInCelcius = 15;
double staticPressureKPA = 13789.4;
double baseStaticPressureKPA = 101.325;

AGAFlowCalculation.Aga7 aga7calc = new AGAFlowCalculation.Aga7();

AGA7Result result = aga7calc.CalculateFlow(flowVolume, flowTemperatureInCelcius,
baseTemperatureInCelcius, staticPressureKPA, baseStaticPressureKPA, meterFactor, 0.848356, 0.997761, 1);

Assert.AreEqual(2.894755, result.Flow, (2.894755 * .001));
}

When performing AGA 11 calculations you can either manually input the compressibility factors or use AGA 8 calculations to calculate the compressibility using the gas compositions.

Contact Us

Redistributable License

  • License will allow a company to build applications that are accessible by both customers and internal employees. 
  • License can be used as a part of an existing application to add real-time gas flow calculations.
  • License does not have limits on the number of developers.
  • License can not be used to offer a free gas flow calculator similar to the SCADACore’s AGA Gas Flow Calculators, SCADACore’s AGA Gas Flow Calculators For Windows, or SCADACore’s Mobile Gas Flow Calculators

Want to know more?

Interested in the AGA Library? You can verify the accuracy of the calculator with the online calculator here: https://www.scadacore.com/tools/aga-calculators/aga-gas-flow-calculator/

Note that the library will provide higher precision numbers compared to the online calculator; and with the full source code, you can use the the library to develop any software or embedded hardware for your application.

  • Do  you need to accurately verify your well flow values?
  • Do you spend hours each month manually calculating flow values?
  • Do you want to automate tedious tasks and save time and money in the process?
  • Do you want to make your job easier?
Contact Us Now!