FE-ISO12213-3-C (Revised: July 28, 2010) is the C source code implementation of the International standard:
Functions | |||
---|---|---|---|
Function 1 | void iso12213x3(struct iso12213 *); | ||
Function 2 | void sgerg1(struct iso12213 *); | ||
Struct | |||
struct iso12213{fpnp p; fpnp t; fpnp mfrCO2; fpnp mfrH2; fpnp rd; fpnp scv; fpnp zf; fpnp d; fpnp md; fpnp mm; long es;}; | |||
Input parameters | |||
Data type | Parameter name | Parameter description | Unit of measure |
fpnp1) | p | Pressure (absolute) | bar |
fpnp | t | Temperature | °C |
fpnp | mfrCO2 | Mole fraction of CO2 | - |
fpnp | scv | Superior calorific value | MJ/m3 |
fpnp | rd | Relative density | - |
fpnp | mfrH2 | Mole fraction of H2 | " |
Output parameters | |||
fpnp | mm | Gas mixture molar mass | kg/kmol |
fpnp | md | Gas mixture molar density | kg⋅mol/m3 |
fpnp | d | Gas mixture density | kg/m3 |
fpnp | zf | Gas mixture compressibility factor | - |
long | es | Error status2) | - |
1)
"fpnp" stands for floating point number precision. It can be defined as single or double precision floating point number. See header file below. |
Ranges of application implemented in FE-ISO12213-3-C | |||
---|---|---|---|
Parameter | Unit of measure | Normal range | Wider range |
p: Pressure (absolute) | MPa | 10-7 to 12 | 10-7 to 12 |
t: Temperature | K | 263 to 338 | 263 to 338 |
rd: Relative density | - | 0.55 to 0.80 | 0.50 to 1.00 |
scv: Superior calorific value | MJ/m3 | 30.0 to 45.0 | 20.0 to 48.0 |
mfrCO2: Molar fraction of Carbon dioxide | - | 0 to 0.20 | 0 to 0.30 |
mfrCO2: Molar fraction of Hydrogen | - | 0 to 0.10 | 0 to 0.10 |
"Normal range" stands for Pipeline quality gas (see Section 4.4.1 of ISO 12213-3:2006). "Wider range" stands for Wider range of application (see Section 4.4.2 of ISO 12213-3:2006). The ranges of application denoted by "Wider range" are implemented in FE-ISO12213-3-C C-code |
#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 iso12213 { /* INPUT PARAMETERS */ fpnp p; /* Pressure in [bar] */ fpnp t; /* Temperature in [degC] */ fpnp mfrCO2; /* mole fraction of CO2 */ fpnp mfrH2; /* mole fraction of H2 */ fpnp rd; /* relative density */ fpnp scv; /* superior calorific value [MJ/m^3] */ /* OUTPUT PARAMETERS */ unsigned long int es; /* Error status */ fpnp zf; /* Compression (compressibility factor) */ fpnp d; /* Density in [kg/m3] */ fpnp md; /* Molar density [kg-mole/m3] */ fpnp mm; /* Molar mass */ }; /* declaration of the function iso12213x3.c */ void iso12213x3(struct iso12213 *); /* declaration of the function sgerg1 */ void sgerg1(struct iso12213 *);
/* ******************* */ /* MAIN PROGRAM C-CODE */ /* ******************* */ #include "iso12213x3.h" void main(void) { struct iso12213 iso[10], *isox; /* 'isox' is a pointer to a structure 'iso' */ unsigned short int j, ii, ix, idx; char ch; char *text[11] = { "Pressure in bar ", "Tempreature in degC ", "mfrCO2 ", "mfrH2 ", "Relative density ", "Superior cal. value ", "Error ststus ", "Compression ", "Density ", "Molar density ", "Molar Mass " }; /* ISO-12213-3 examples */ /* p, t, mfrCO2, mfrH2, rd, scv */ fpnp xx[60][6] = { 60, -3.15, 0.006, 0.000, 0.581, 40.66, 60, 6.85, 0.006, 0.000, 0.581, 40.66, 60, 16.85, 0.006, 0.000, 0.581, 40.66, 60, 36.85, 0.006, 0.000, 0.581, 40.66, 60, 56.85, 0.006, 0.000, 0.581, 40.66, 120, -3.15, 0.006, 0.000, 0.581, 40.66, 120, 6.85, 0.006, 0.000, 0.581, 40.66, 120,16.85, 0.006, 0.000, 0.581, 40.66, 120, 36.85, 0.006, 0.000, 0.581, 40.66, 120, 56.85, 0.006, 0.000, 0.581, 40.66, 60, -3.15, 0.005, 0.000, 0.609, 40.62, 60, 6.85, 0.005, 0.000, 0.609, 40.62, 60, 16.85, 0.005, 0.000, 0.609, 40.62, 60, 36.85, 0.005, 0.000, 0.609, 40.62, 60, 56.85, 0.005, 0.000, 0.609, 40.62, 120, -3.15, 0.005, 0.000, 0.609, 40.62, 120, 6.85, 0.005, 0.000, 0.609, 40.62, 120,16.85, 0.005, 0.000, 0.609, 40.62, 120, 36.85, 0.005, 0.000, 0.609, 40.62, 120, 56.85, 0.005, 0.000, 0.609, 40.62, 60, -3.15, 0.015, 0.000, 0.650, 43.53, 60, 6.85, 0.015, 0.000, 0.650, 43.53, 60, 16.85, 0.015, 0.000, 0.650, 43.53, 60, 36.85, 0.015, 0.000, 0.650, 43.53, 60, 56.85, 0.015, 0.000, 0.650, 43.53, 120, -3.15, 0.015, 0.000, 0.650, 43.53, 120, 6.85, 0.015, 0.000, 0.650, 43.53, 120,16.85, 0.015, 0.000, 0.650, 43.53, 120, 36.85, 0.015, 0.000, 0.650, 43.53, 120, 56.85, 0.015, 0.000, 0.650, 43.53, 60, -3.15, 0.016, 0.095, 0.599, 34.16, 60, 6.85, 0.016, 0.095, 0.599, 34.16, 60, 16.85, 0.016, 0.095, 0.599, 34.16, 60, 36.85, 0.016, 0.095, 0.599, 34.16, 60, 56.85, 0.016, 0.095, 0.599, 34.16, 120, -3.15, 0.016, 0.095, 0.599, 34.16, 120, 6.85, 0.016, 0.095, 0.599, 34.16, 120,16.85, 0.016, 0.095, 0.599, 34.16, 120, 36.85, 0.016, 0.095, 0.599, 34.16, 120, 56.85, 0.016, 0.095, 0.599, 34.16, 60, -3.15, 0.076, 0.000, 0.686, 36.64, 60, 6.85, 0.076, 0.000, 0.686, 36.64, 60, 16.85, 0.076, 0.000, 0.686, 36.64, 60, 36.85, 0.076, 0.000, 0.686, 36.64, 60, 56.85, 0.076, 0.000, 0.686, 36.64, 120, -3.15, 0.076, 0.000, 0.686, 36.64, 120, 6.85, 0.076, 0.000, 0.686, 36.64, 120,16.85, 0.076, 0.000, 0.686, 36.64, 120, 36.85, 0.076, 0.000, 0.686, 36.64, 120, 56.85, 0.076, 0.000, 0.686, 36.64, 60, -3.15, 0.011, 0.000, 0.644, 36.58, 60, 6.85, 0.011, 0.000, 0.644, 36.58, 60, 16.85, 0.011, 0.000, 0.644, 36.58, 60, 36.85, 0.011, 0.000, 0.644, 36.58, 60, 56.85, 0.011, 0.000, 0.644, 36.58, 120, -3.15, 0.011, 0.000, 0.644, 36.58, 120, 6.85, 0.011, 0.000, 0.644, 36.58, 120,16.85, 0.011, 0.000, 0.644, 36.58, 120, 36.85, 0.011, 0.000, 0.644, 36.58, 120, 56.85, 0.011, 0.000, 0.644, 36.58 }; for (j=0; ; ) { ii=0; printf("\n\nSelect input parameter setup '0' or ISO-12213-3 gas example '1-6'."; printf("\n Type number between 0 and 6: "); scanf("%d", &(ii)); if(ii>0 && ii<=6) { idx = (ii-1)*10; for (ix=0; ix<=9; ix++) { iso[ix].p=xx[ix+idx][0]; iso[ix].t=xx[ix+idx][1]; iso[ix].mfrCO2=xx[ix+idx][2]; iso[ix].mfrH2=xx[ix+idx][3]; iso[ix].rd=xx[ix+idx][4]; iso[ix].scv=xx[ix+idx][5]; } } else { printf("%s = ", text[0]); scanf("%lf", &(iso[0].p)); printf("%s = ", text[1]); scanf("%lf", &(iso[0].t)); printf("%s = ", text[2]); scanf("%lf", &(iso[0].mfrCO2)); printf("%s = ", text[3]); scanf("%lf", &(iso[0].mfrH2)); printf("%s = ", text[4]); scanf("%lf", &(iso[0].rd)); printf("%s = ", text[4]); scanf("%lf", &(iso[0].scv)); } if(ii>0 && ii<=6) { printf("\nCOMPRESSION FACTOR (ISO-12213-3, Table C.1): Gas %d", ii); for (ix=0; ix<=9; ix++) { isox = &iso[ix]; /* Put the address of the 'iso' structure into 'isox' */ iso12213x3(isox); /* Call function by passing the pointer to structure */ printf("\nZ%d = %lf",ix+1, iso[ix].zf); } } else { isox = &iso[0]; /* Put the address of 'iso' structure into 'isox' */ iso12213x3(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:"); printf("\n%s = %lf",text[0], iso[0].p); printf("\n%s = %lf",text[1], iso[0].t); printf("\n%s = %lf",text[2], iso[0].mfrCO2); printf("\n%s = %lf",text[3], iso[0].mfrH2); printf("\n%s = %lf",text[4], iso[0].rd); printf("\n%s = %lf",text[5], iso[0].scv); printf("\nO U T P U T P A R A M E T E R S:"); printf("\n%s = %xH",text[6], iso[0].es); printf("\n%s = %lf",text[7], iso[0].zf); printf("\n%s = %lf",text[8], iso[0].d); printf("\n%s = %lf",text[9], iso[0].md); printf("\n%s = %lf",text[10], iso[0].mm); } 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 */ /* ****************************** */