FE-ISO20765-1-C (Revised: February 19, 2010) is the C source code implementation of the International standard:
Function | |
---|---|
Function declaration | void iso20765x1(struct iso20765 *); |
Struct iso20765{fpnp xx[42]; unsigned long int es;} | |
INPUT parameters | |
fpnp1) xx[0] | Mole fraction of — Methane |
fpnp xx[1] | Mole fraction of — Nitrogen |
fpnp xx[2] | Mole fraction of — Carbon Dioxide |
fpnp xx[3] | Mole fraction of — Ethane |
fpnp xx[4] | Mole fraction of — Propane |
fpnp xx[5] | Mole fraction of — Water |
fpnp xx[6] | Mole fraction of — Hydrogen-sulfide |
fpnp xx[7] | Mole fraction of — Hydrogen |
fpnp xx[8] | Mole fraction of — Carbon-monoxide |
fpnp xx[9] | Mole fraction of — Oxygen |
fpnp xx[10] | Mole fraction of — Isobutane |
fpnp xx[11] | Mole fraction of — n-Butane |
fpnp xx[12] | Mole fraction of — Isopentane |
fpnp xx[13] | Mole fraction of — n-Pentane |
fpnp xx[14] | Mole fraction of — n-Hexane |
fpnp xx[15] | Mole fraction of — n-Heptane |
fpnp xx[16] | Mole fraction of — n-Octane |
fpnp xx[17] | Mole fraction of — n-Nonane |
fpnp xx[18] | Mole fraction of — n-Decane |
fpnp xx[19] | Mole fraction of — Helium |
fpnp xx[20] | Mole fraction of — Argon |
fpnp xx[21] | Pressure (absolute) in MPa |
fpnp xx[22] | Temperature in K |
RESULTS | |
fpnp xx[23] | Natural gas mixture average molar mass [kg/kmol] |
fpnp xx[24] | Natural gas molar density [kg⋅mole/m3] |
fpnp xx[25] | Natural gas density [kg/m3] |
fpnp xx[26] | Natural gas compression (compressibility factor) |
fpnp xx[27] | Natural gas density to air density ratio at T2=273.15 K, p2=0.101325 MPa |
fpnp xx[28] | Superior calorific value [MJ/m3] on a volumetric basis at reference conditions for: Combustion: T1=298.15 K, p1=0.101325 MPa Metering: T2=273.15 K, p2=0.101325 MPa |
fpnp xx[29] | Molar internal energy [kJ/kmol] |
fpnp xx[30] | Specific internal energy [kJ/kg] |
fpnp xx[31] | Molar Enthalpy [kJ/kmol] |
fpnp xx[32] | Specific enthalpy [kJ/kg] |
fpnp xx[33] | Molar entropy [kJ/(kmol⋅K)] |
fpnp xx[34] | Specific entropy [kJ/(kg⋅K)] |
fpnp xx[35] | Molar isochoric heat capacity [kJ/(kmol⋅K)] |
fpnp xx[36] | Specific isochoric heat capacity [kJ/(kg⋅K)] |
fpnp xx[37] | Molar isobaric heat capacity [kJ/(kmol⋅K)] |
fpnp xx[38] | Specific isobaric heat capacity [kJ/(kg⋅K)] |
fpnp xx[39] | Joule-Thomson coefficient [K/MPa] |
fpnp xx[40] | Isentropic exponent [] |
fpnp xx[41] | Speed of sound [m/s] |
long es 2) | Error status after completion of the calculation method |
Ranges of application implemented in FE-ISO20765-1-C | |
---|---|
Parameter | Range |
Pressure (absolute) in MPa | 10-7 to 35 |
Temperature in K | 250 to 350 |
Relative density | 0.55 to 0.90 |
Superior calorific value in MJ/m3 | 20 to 48/td> |
Mole fractions ranges | |
Methane | 0.7 to 1.00 | Nitrogen | 0 to 0.20 |
Carbon dioxide | 0 to 0.20 |
Ethane | 0 to 0.10 |
Propane | 0 to 0.035 | Water | 0 to 0.00015 |
Hydrogen sulfide | 0 to 0.0002 |
Hydrogen | 0 to 0.10 |
Carbon monoxide | 0 to 0.03 |
Oxigen | 0 to 0.0002 |
Butanes | 0 to 0.015 |
Pentanes | 0 to 0.005 |
Hexanes | 0 to 0.001 |
Heptanes | 0 to 0.0005 |
Octanes plus higher hydrocarbons | 0 to 0.0005 |
Helium | 0 to 0.005 |
Argon | 0 to 0.0002 |
1)
"fpnp" stands for floating point number precision. It can be defined as single or double precision floating point number. See header file below. |
#include "stdio.h" #include "math.h" /* IN CASE OF SINGLE FLOATING POINT NUMBER PRECISION */ /* #define fpnp float */ /* IN CASE OF Double FLOATING POINT NUMBER PRECISION */ /* #define fpnp double */ #define fpnp double /* declaration of the structure */ struct iso20765 { /* INPUT/OUTPUT PARAMETERS SEE BELOW*/ fpnp xx[42]; /* Parameters in floating point format */ unsigned long int es; /* Error status */ }; /* declaration of the function iso20765x1.c */ void iso20765x1(struct iso20765 *); /* input/output parameters */
/* ******************* */ /* MAIN PROGRAM C-CODE */ /* ******************* */ #include "iso20765x1.h" void main(void) { struct iso20765 iso, *isox; /* 'isox' is a pointer to a structure 'iso' */ unsigned short int j, ii, ix; char ch; char *text[43] = { "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 factor ", "Relative density ", "Superior calorific value kJ/(kg.K) ", "Molar internal energy kJ/kmol ", "Specific internal energy kJ/kg ", "Molar enthalpy kJ/kmol ", "Specific enthalpy kJ/kg ", "Molar entropy kJ/(kmol.K) ", "Specific entropy kJ/(kg.K) ", "Molar isochoric heat capacity kJ/(kmol.K) ", "Specific isochoric heat capacity kJ/(kg.K) ", "Molar isobaric heat capacity kJ/(kmol.K) ", "Specific isobaric heat capacity kJ/(kg.K) ", "Joule-Thomson coefficient K/MPa ", "Isentropic exponent ", "Speed of sound m/s ", "Error status " }; /* ISO-20765-1, Annex G, Table G.1: example calculations Gas1,..., Gas6 */ /* Molar fractions of natural gas components: */ /* Methane, Nitrogen, Carbon diox., Ethane, Propane, Water, Hydrogen s., */ /* Hydrogen, Carbon m., Oxygen, iso-Butane, n-Butane, iso-Pentane, n-Pentane, */ /* n-Hexane, n-Heptane, n-Octane, n-Nonane, n-Decane, Helium, Argon */ fpnp mf[6][21] = { 0.965000, 0.003000, 0.006000, 0.018000, 0.004500, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.001000, 0.001000, 0.000500, 0.000300, 0.000700, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.907000, 0.031000, 0.005000, 0.045000, 0.008400, 0.000100, 0.000100, 0.000000, 0.000000, 0.000100, 0.001000, 0.001500, 0.000300, 0.000400, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000100, 0.859284, 0.009617, 0.015021, 0.084563, 0.023022, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.006985, 0.000000, 0.001218, 0.000228, 0.000057, 0.000005, 0.000000, 0.000000, 0.000000, 0.000000, 0.735000, 0.100000, 0.016000, 0.033000, 0.007400, 0.000100, 0.000100, 0.095000, 0.010000, 0.000100, 0.000800, 0.000800, 0.000400, 0.000400, 0.000200, 0.000100, 0.000100, 0.000100, 0.000100, 0.000200, 0.000100, 0.812000, 0.057000, 0.076000, 0.043000, 0.009000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.001500, 0.001500, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.825198, 0.117266, 0.011093, 0.034611, 0.007645, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.002539, 0.000000, 0.000746, 0.000225, 0.000110, 0.000029, 0.000000, 0.000000, 0.000538, 0.000000 }; for (j=0; ;) { ii=0; printf("\n\nSelect input parameter setup '0' or ISO-20765-1 gas mixture '1-6'.\n Type number between 0 and 6: "); scanf("%d", &(ii)); if(ii>0 && ii<=6) { for (ix=0; ix<=20; ix++) { iso.xx[ix]=mf[ii-1][ix]; } printf("\nGas %d:\n", ii); for (ix=21; ix<=22; ix++) { printf("%s = ", text[ix]); scanf("%lf", &(iso.xx[ix])); } } else { printf("\nMole fraction of:\n"); for (ix=0; ix<=22; ix++) { printf("%s = ", text[ix]); scanf("%lf", &(iso.xx[ix])); } } isox = &iso; /* Put the address of 'iso' structure into 'isox' */ iso20765x1(isox); /* Call function by passing the pointer to structure */ /* Print input parameters */ printf("\nI N P U T P A R A M E T E R S:"); for (ix=0; ix<=22; ix++) { printf("\n%s = %lf",text[ix], iso.xx[ix]); } printf("\nO U T P U T P A R A M E T E R S:"); printf("\n%s = %xH",text[42], iso.es); for (ix=23; ix<=41; ix++) { printf("\n%s = %lf",text[ix], iso.xx[ix]); } printf("\nPress X to exit or anything else to continue: "); ch = getch(); if (( ch == 'X') || (ch == 'x')) break; } } /* ****************************** */ /* END OF THE MAIN PROGRAM C-CODE */ /* ****************************** */