aga92dc.c - Instructions for use

Revision: July 28, 2010

 

E-mail: info@felib.com

 

aga92dc.c is the C source code implementation of the International standard

ISO 12213-2:2006: Natural gas - Calculation of compression factor -

Part 2: Calculation using molar-composition analysis

 

The software is written in a C-language and embeds all the restrictions implied by ISO-12213-2.

 

1. Function prototype

 

The following is the definition of the function prototype:

 

void aga92dc(

/* output parameters */

unsigned long int *error_status, /* Error status */

float *sup_cal_value, /* Superior calorific value */

float *relative_density, /* Relative density */

float *compression, /* Compression (compressibility factor) */

float *density, /* Density [kg/m3] */

float *molar_density, /* Molar density [kg-mole/m3] */

float *mole_average, /* Mole average */

/* input parameters */

float tepmerature_K, /* Temperature [K] */

float pressure_MPa, /* Pressure in [MPa] */

float x20, /* molar fraction of Argon */

float x19, /* molar fraction of Helium */

float x18, /* molar fraction of n-Decane */

float x17, /* molar fraction of n-Nonane */

float x16, /* molar fraction of n-Octane */

float x15, /* molar fraction of n-Heptane */

float x14, /* molar fraction of n-Hexane */

float x13, /* molar fraction of n-Pentane */

float x12, /* molar fraction of i-Pentane */

float x11, /* molar fraction of n-Butane */

float x10, /* molar fraction of i-Butane */

float x9, /* molar fraction of Oxygen */

float x8, /* molar fraction of Carbon Monoxide */

float x7, /* molar fraction of Hydrogen */

float x6, /* molar fraction of Hydrogen Sulfide */

float x5, /* molar fraction of Water */

float x4, /* molar fraction of Propane */

float x3, /* molar fraction of Ethane */

float x2, /* molar fraction of Carbon Dioxide */

float x1, /* molar fraction of Nitrogen */

float x0 /* molar fraction of Methane */

)


2. Input and output parameters

 

The following Table shows the description of input and output parameters:

 

Table 2.1

 

Input parameters

Data type

Parameter name

Parameter description

Unit of measure

float

x0

molar fraction of Methane

dimensionless

float

x1

molar fraction of Nitrogen

"

float

x2

molar fraction of Carbon dioxide

"

float

x3

molar fraction of Ethane

"

float

x4

molar fraction of Propane

"

float

x5

molar fraction of Water

"

float

x6

molar fraction of Hydrogen sulfide

"

float

x7

molar fraction of Hydrogen

"

float

x8

molar fraction of Carbon monoxide

"

float

x9

molar fraction of Oxygen

"

float

x10

molar fraction of iso-Butane

"

float

x11

molar fraction of n-Butane

"

float

x12

molar fraction of i-Pentane

"

float

x13

molar fraction of n-Pentane

"

float

x14

molar fraction of n-Hexane

"

float

x15

molar fraction of n-Heptane

"

float

x16

molar fraction of n-Octane

"

float

x17

molar fraction of n-Nonane

"

float

x18

molar fraction of n-Decane

"

float

x19

molar fraction of Helium

"

float

x20

molar fraction of Argon

"

float

pressure_MPa

operating pressure

[MPa]

float

temperature_K

operating temperature

[K]

Output parameters

float

mole_average

gas mixture molar mass

dimensionless

float

molar_density

gas mixture molar density

[kgmol/m3]

float

density

gas mixture density

[kg/m3]

float

compression

gas mixture compression factor

dimensionless

float

relative density

gas mixture relative density

"

float

sup_cal_value

gas mixture superior calorific value

[MJ/m3]

unsigned long int

error_status

error status

dimensionless

 


3. Parameter ranges

 

The following Table shows the ranges for input parameters and intermediate results, as defined by ISO 12213-2.

 

Table 3.1

 

Component

Unit of measure

A*

B**

methane

dimensionless

0.70 to 1.00

0.50 to 1.00

nitrogen

"

0 to 0.20

0 to 0.50

carbon dioxide

"

0 to 0.20

0 to 0.30

ethane

"

0 to 0.10

0 to 0.20

propane

"

0 to 0.035

0 to 0.05

butanes (n-Butane + i-Butane)

"

0 to 0.015

0 to 0.0015

pentanes (n-pentane + i-Pentane)

"

0 to 0.005

0 to 0.005

hexanes (n-Hexane)

"

0 to 0.001

0 to 0.001

heptanes (n-Heptane)

"

0 to 0.0005

0 to 0.0005

octanes plus higher hydrocarbons

(n-Octane, n-Nonane, n-Decane)

"

0 to 0.0005

0 to 0.0005

hydrogen

"

0 to 0.10

0 to 0.10

carbon monoxide

"

0 to 0.03

0 to 0.003

helium

"

0 to 0.005

0 to 0.005

water

"

0 to 0.015

0 to 0.00015

argon

"

0 to 0.0002

0 to 0.0002

absolute pressure

[MPa]

0 to 12

0 to 65

temperature

[K]

263 to 338

225 to 350

relative density

dimensionless

0.55 to 0.80

0.55 to 0.90

superior calorific value

[MJ/m3]

30 to 45

20 to 48

 

* A: pipeline quality natural gas

** B: wider ranges of application

 

The wider ranges of application (B) are implemented in aga92dc routine

 


 

4. Error status

 

After completion of the routine the error_status (unsigned long integer) will be cleared if there were no errors during the calculation, or the corresponding bits will be set if certain errors were encountered. The error_status is represented in the following way:

 

 

Bit 0 =1 (000001H) If there exist at least one molar fraction < 0, else =0.

Bit 1 =1 (000002H) If the total sum of molar fractions <0.98 or >1.02, else =0.

Bit 2 =1 (000004H) If the total sum of molar fractions is <0.999999 or >1.000001, else =0. This bit denotes only a warning that the fractions have been normalized to give the total sum of molar fractions equal to 1. If only bit 2 was set during the calculation the results are valid.

Bit 3 =1 (000008H) If mole fraction of Methane <0.5 or >1.0, else =0.

Bit 4 =1 (000010H) If mole fraction of Nitrogen >0.5, else =0.

Bit 5 =1 (000020H) If mole fraction of Carbon Dioxide >0.3, else =0.

Bit 6 =1 (000040H) If mole fraction of Ethane >0.2, else =0.

Bit 7 =1 (000080H) If mole fraction of Propane >0.05, else =0.

Bit 8 =1 (000100H) If mole fraction of Water >0.00015, else =0.

Bit 9 =1 (000200H) If mole fraction of Hydrogen sulfide > 0.0002, else =0.

Bit 10 =1 (000400H) If mole fraction of Hydrogen >0.10, else =0.

Bit 11 =1 (000800H) If mole fraction of Carbon monoxide > 0.03, else =0.

Bit 12 =1 (001000H) If mole fraction of Oxygen >0.0002, else =0.

Bit 13 =1 (002000H) If mole fraction of Butanes (n-Butane + i-Butane) >0.015, else =0.

Bit 14 =1 (004000H) If mole fraction of Pentanes (n-pentane + i-Pentane) >0.005, else =0.

Bit 15 =1 (008000H) If mole fraction of Hexanes (n-Hexane) >0.001, else =0.

Bit 16 =1 (010000H) If mole fraction of Heptanes (n-Heptane) >0.0005, else =0.

Bit 17 =1 (020000H) If mole fraction of octanes plus higher hydrocarbons (n-Octane + n-Nonane, n-Decane) >0.01, else =0.

Bit 18 =1 (040000H) If mole fraction of Helium >0.005, else =0.

Bit 19 =1 (080000H) If mole fraction of Argon >0.0002, else =0.

Bit 20 =1 (100000H) If pressure <0.1 Pa or >65 MPa, else =0.

Bit 21 =1 (200000H) If temperature <225 K or >350 K, else =0.

Bit 22 =1 (400000H) If relative density <0.55 or >0.90, else =0.

Bit 23 =1 (800000H) If superior calorific value <20 MJ/m3 or >48 MJ/m3, else =0.

Bit 24 =1 (1000000H) If OFF-LINE calculation failed, else=0.

Bit 25,... All higer bits are unused

 

The error_status is returned as unsigned long integer representing all the errors encountered in the calculation. If bits 0,...,24 are all cleared, or if only bit 2 was set during the calculation, the returned output results are valid, otherwise the results are invalid, i.e. cleared.

 


5. Example of a main program calling the function aga92dc

 

 

The following example illustrates the call to aga92dc function from a main program. Input parameters yy[igas][0], ..., yy[igas][20] represent natural gas mixture molar fractions where igas = 0 denotes Gas 1, ..., igas =5 denotes Gas 6 (See table 6.1 in chapter 6), yy[21] represents operating pressure (6 MPa) and yy[22] represents temperature 310 K. The output results are saved in yy[23], ..., yy[28] and an error status in error, after the completion of the routine. The program prompts for the selection of the gas mixture, for the operating pressure and temperature and prints the results on the screen.

 

/* **************************************** */

/* THE BEGINNING OF THE MAIN PROGRAM C-CODE */

/* **************************************** */

 

#include "stdio.h"

/* declaration of the function aga92dc */

void aga92dc(

/* output parameters */

unsigned long int *error_status, /* Error status */

float *sup_cal_value, /* Superior calorific value */

float *relative_density, /* Relative density */

float *compression, /* Compression (compressibility factor) */

float *density, /* Density [kg/m3] */

float *molar_density, /* Molar density [kg-mole/m3] */

float *mole_average, /* Mole average */

 

/* input parameters */

float tepmerature_K, /* Temperature [K] */

float pressure_MPa, /* Pressure in [MPa] */

float x20, /* molar fraction of Argon */

float x19, /* molar fraction of Helium */

float x18, /* molar fraction of n-Decane */

float x17, /* molar fraction of n-Nonane */

float x16, /* molar fraction of n-Octane */

float x15, /* molar fraction of n-Heptane */

float x14, /* molar fraction of n-Hexane */

float x13, /* molar fraction of n-Pentane */

float x12, /* molar fraction of i-Pentane */

float x11, /* molar fraction of n-Butane */

float x10, /* molar fraction of i-Butane */

float x9, /* molar fraction of Oxygen */

float x8, /* molar fraction of Carbon Monoxide */

float x7, /* molar fraction of Hydrogen */

float x6, /* molar fraction of Hydrogen Sulfide */

float x5, /* molar fraction of Water */

float x4, /* molar fraction of Propane */

float x3, /* molar fraction of Ethane */

float x2, /* molar fraction of Carbon Dioxide */

float x1, /* molar fraction of Nitrogen */

float x0 /* molar fraction of Methane */

);

 

void main(void)

{

unsigned short int i, j, igas;

unsigned long int error;

char ch;

 

/* Array of input and output data */

float twodim[2][3] = { 11, 12, 13, 21, 22, 23 };

 

float yy[6][29] = {

0.965, 0.003, 0.006, 0.018, 0.0045, 0.0, 0.0,

0.0, 0.0, 0.0, 0.001, 0.001, 0.0005, 0.0003,

0.0007, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

 

0.907, 0.031, 0.005, 0.045, 0.0084, 0.0, 0.0,

0.0, 0.0, 0.0, 0.001, 0.0015, 0.0003, 0.0004,

0.0004, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

 

0.859, 0.01, 0.015, 0.085, 0.023, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0035, 0.0035, 0.0005, 0.0005,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

 

0.735, 0.1, 0.016, 0.033, 0.0074, 0.0, 0.0,

0.095, 0.01, 0.0, 0.0012, 0.0012, 0.0004, 0.0004,

0.0002, 0.0001, 0.0001, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

 

0.812, 0.057, 0.076, 0.043, 0.009, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0015, 0.0015, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,

 

0.826, 0.117, 0.011, 0.035, 0.0075, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0012, 0.0012, 0.0004, 0.0004,

0.0002, 0.0001, 0.0, 0.0, 0.0, 0.0, 0.0,

0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

};

 

 

char *text[29] = {

"Methane ", "Nitrogen ", "Carbon Dioxide ",

"Ethane ", "Propane ", "Water ",

"Hydrogen Sulfide", "Hydrogen ", "Carbon Monoxide ",

"Oxygen ", "iso-Butane ", "n-Butane ",

"i-Pentane ", "n-Pentane ", "n-Hexane ",

"n-Heptane ", "n-Octane ", "n-Nonane ",

"n-Decane ", "Helium ", "Argon ",

"Pressure [MPa] ", "Temperature [K] ",

"Mole average ",

"Molar density [kg-mole/m3]",

"Density [kg/m3] ",

"Compression ",

"Relative density ",

"Superior calorific value "

};

 

for (j=0; ; ) {

printf("\nINPUT PARAMETERS\n");

printf("%s", "Select gas composition (type number 1-6) = ");

scanf("%d", &igas);

if (igas > 6)

igas = 6;

igas -= 1;

/* Enter parameters */

for (i=21; i<23; ++i) {

printf("%s = ", text[i]);

/* Enter parameter */

scanf("%f", &yy[igas][i]);

}

/* Print input parameters and results */

printf("\nI N P U T P A R A M E T E R S:");

/* Print gas selection */

printf("\n%s%d", "Selected gas = Gas", igas+1);

/* Print mole fractions */

printf("\nMole fractions:");

for (i=0; i<10; ++i) {

printf("\n%s = %f, %s = %f",text[2*i], yy[igas][2*i], text[2*i+1], \

yy[igas][2*i+1]);

}

printf("\n%s = %f",text[20], yy[igas][20]);

/* Print pressure */

printf("\n%s = %f", text[21], yy[igas][21]);

/* Print temperature */

printf("\n%s = %f", text[22], yy[igas][22]);

printf("\n\nR E S U L T S");

/* call aga8/1992 routine */

 

/* for (i=0; i<10000; ++i) { */

aga92dc(&error,

&yy[igas][28], &yy[igas][27], &yy[igas][26], &yy[igas][25], \

&yy[igas][24], &yy[igas][23], yy[igas][22], yy[igas][21], \

yy[igas][20], yy[igas][19], yy[igas][18], yy[igas][17], yy[igas][16], \

yy[igas][15], yy[igas][14], yy[igas][13], yy[igas][12], yy[igas][11], \

yy[igas][10], yy[igas][9], yy[igas][8], yy[igas][7], yy[igas][6], \

yy[igas][5], yy[igas][4], yy[igas][3], yy[igas][2], yy[igas][1], \

yy[igas][0]);

/* } */

/* Print error flags as hexadecimal number */

printf("\nError(Hex) = %x", error);

/* Print results */

for (i=0; i<6; ++i) {

printf("\n%s = %f",text[28-i], yy[igas][28-i]);

}

printf("\nPress X to exit or anything else to continue: ");

ch = getch();

if (( ch == 'X') || (ch == 'x'))

break;

}

}

 

/* ********************************** */

/* THE END OF THE MAIN PROGRAM C-CODE */

/* ********************************** */


6. Examples for the verification of the program

 

The following table contains the example calculations that are retyped from Annex C of ISO-12213-2. Refer to Annex C in order to avoid possible typing errors.

 

Table 6.1

 

 

Molar fractions of the gas mixture components

Component

Gas 1

Gas 2

Gas 3

Gas 4

Gas 5

Gas 6

Methane

0.965

0.907

0.859

0.735

0.812

0.826

Nitrogen

0.003

0.031

0.01

0.1

0.057

0.117

Carbon dioxide

0.006

0.005

0.015

0.016

0.076

0.011

Ethane

0.018

0.045

0.085

0.033

0.043

0.035

Propane

0.0045

0.0084

0.023

0.0074

0.009

0.0075

Water

0.0

0.0

0.0

0.0

0.0

0.0

Hydrogen sulfide

0.0

0.0

0.0

0.0

0.0

0.0

Hydrogen

0.0

0.0

0.0

0.095

0.0

0.0

Carbon monoxide

0.0

0.0

0.0

0.01

0.0

0.0

Oxygen

0.0

0.0

0.0

0.0

0.0

0.0

iso-Butane

0.001

0.001

0.0035

0.0012

0.0015

0.0012

n-Butane

0.001

0.0015

0.0035

0.0012

0.0015

0.0012

i-Pentane

0.0005

0.0003

0.0005

0.0004

0.0

0.0004

n-Pentane

0.0003

0.0004

0.0005

0.0004

0.0

0.0004

n-Hexane

0.0007

0.0004

0.0

0.0002

0.0

0.0002

n-Heptane

0.0

0.0

0.0

0.0001

0.0

0.0001

n-Octane

0.0

0.0

0.0

0.0001

0.0

0.0

n-Nonane

0.0

0.0

0.0

0.0

0.0

0.0

n-Decane

0.0

0.0

0.0

0.0

0.0

0.0

Helium

0.0

0.0

0.0

0.0

0.0

0.0

Argon

0.0

0.0

0.0

0.0

0.0

0.0

Conditions

 

Results Z-values

p

[MPa]

T

[K]

6

270

0.84053

0.83348

0.79380

0.88550

0.82609

0.85380

6

280

0.86199

0.85596

0.82206

0.90144

0.84969

0.87370

6

290

0.88006

0.87484

0.84544

0.91501

0.86944

0.89052

6

310

0.90867

0.90466

0.88183

0.93674

0.90052

0.91723

6

330

0.93011

0.92696

0.90868

0.95318

0.92368

0.93730

12

270

0.72133

0.71044

0.64145

0.81024

0.69540

0.75074

12

280

0.76025

0.75066

0.68971

0.83782

0.73780

0.78586

12

290

0.79317

0.78475

0.73123

0.86137

0.77369

0.81569

12

310

0.84515

0.83863

0.79698

0.89913

0.83022

0.86311

12

330

0.88383

0.87870

0.84553

0.92766

0.87211

0.89862