FE-ISO5167-C


FE-ISO5167-C (Revised: February 6, 2018) is the C source code implementation of the following International standards:

ISO 5167: Measurement of fluid flow by means of pressure differential devices inserted in circular cross-section conduits running full

  • ISO 5167-1:2003 - Part 1: General principles and requirements
  • ISO 5167-2:2003 - Part 2: Orifice plates
  • ISO 5167-3:2003 - Part 3: Nozzles and Venturi nozzles
  • ISO 5167-4:2003 - Part 4: Venturi tubes
  • ISO 5167-5:2016 - Part 5: Cone meters

FE-ISO5167-C enables the computation of:

  • flowrate
  • differential pressure
  • pipe diameter
  • diameter of pressure differential device

Description of function, parameters and errors

Function
Function declaration void iso5167(short iCalc, struct iso5167 *);
short iCalc defines the following four types of calculation
iCalc=0 the function calculates the flowrate, Reynolds number, discharge coefficient, expansion factor, beta ratio and sets the error status "long errflag" (see below)
iCalc=1 the function calculates the differential pressure, Reynolds number, discharge coefficient, expansion factor, beta ratio and sets and sets the error status "long errflag" (see below)
iCalc=2 the function calculates the diameter of a pressure differential device, Reynolds number, discharge coefficient, expansion factor, beta ratio and sets the error status "long errflag" (see below)
iCalc=3 the function calculates the diameter of pipe, Reynolds number, number, discharge coefficient, expansion factor and sets the error status "long errflag" (see below)
Struct iso5167{}
Struct iso5167{}: input parameters common to all four types of calculation
fpnp1 p absolute pressure p[Pa] (0.001 ≤ p ≤1.0E+9)
fpnp1 t temperature t[degC] (-273.15 ≤ t ≤ 1000000)
short ft type of fluid ft(ft=0, gas; ft=1, liquid)
fpnp1 d fluid density d[kg/m^3] (0.000001 ≤ d ≤ 10000)
fpnp1 v dynamic viscosity of the fluid v[Pa*s] (0.0 ≤ v ≤ 10.0)
fpnp1 ie isentropic exponent ie[] (0.1 ≤ ie ≤ 2000 for gases, 0 for liquids)
short ddt Pressure differential device type: (0 ≤ ddt ≤ 9)
  • ddt = 0 → Orifice with flange tappings
  • ddt = 1 → Orifice with corner tappings
  • ddt = 2 → Orifice with D and D/2 tappings
  • ddt = 3 → Classical Venturi tube with a machined inlet
  • ddt = 4 → Classical Venturi tube with a rough cast inlet
  • ddt = 5 → Classical Venturi tube with a rough-welded sheet-iron inlet
  • ddt = 6 → Long radius nozzle
  • ddt = 7 → ISA 1932 nozzle
  • ddt = 8 → Venturi nozzle (ISA inlet)
  • ddt = 9 → Cone meter
short ud upstream/downstream pressure measurement
  • ud = 0 → upstream pressure measurement
  • ud = 1 → downstream pressure measurement
Struct iso5167 {}: input or output members, depending on the calculation type
fpnp1 dp differential pressure dp[Pa]: ((p-dp)/p ≤ 0.75)
  • input if iCalc=0 or 2 or 3
  • output if iCalc=1
fpnp1 od Orifice or throat or cone diameter od[mm]
  • input if iCalc = 0 or 1
  • output if iCalc = 2 or 3

Restrictions on orifice diameter 'od' depend on differential device type 'ddt':

  • ddt=0 → 12.500mm ≤ od ≤ 750
  • ddt=1 → 12.500mm ≤ od ≤ 750
  • ddt=2 → 12.500mm ≤ od ≤ 750
  • ddt=3 → 30.000mm ≤ od ≤ 187.5
  • ddt=4 → 20.000mm ≤ od ≤ 600
  • ddt=5 → 80.000mm ≤ od ≤ 840
  • ddt=6 → 10.000mm ≤ od ≤ 504
  • ddt=7 → 15.000mm ≤ od ≤ 400
  • ddt=8 → 50.000mm ≤ od ≤ 387.5
  • ddt=9 → 33.071mm ≤ od ≤ 446.514
fpnp1 br Beta ratio br[]
  • input if iCalc=3
  • output if iCalc=0 or 1 or 2
fpnp1 pd pipe diameter pd[mm]
  • input if iCalc=3
  • output if iCalc=0 or 1 or 2

Restrictions on pipe diameter 'pd' depend on differential device type 'ddt':

  • ddt=0 → 50mm ≤ pd ≤ 1000mm
  • ddt=1 → 50mm ≤ pd ≤ 1000mm
  • ddt=2 → 50mm ≤ pd ≤ 1000mm
  • ddt=3 → 100mm ≤ pd ≤ 800mm
  • ddt=4 → 50mm ≤ pd ≤ 250mm
  • ddt=5 → 200mm ≤ pd ≤ 1200mm
  • ddt=6 → 50mm ≤ pd ≤ 630mm
  • ddt=7 → 50mm ≤ pd ≤ 500mm
  • ddt=8 → -65mm ≤ pd ≤ 500mm
  • ddt=9 → 50mm ≤ pd ≤ 500mm
fpnp1 mfr Mass flow-rate mfr[kg/h], ): (0.001 ≤ mfr[kg/h] ≤ 109)
  • input if iCalc=1 or 2 or 3
  • output if iCalc=0

Restrictions on mass flow-rate 'mfr':

  • 0.001 ≤ mfr[kg/h] ≤ 109
Struct iso5167{}: output members (results) common to all four types of calculations
fpnp1 rd Reynolds number []
fpnp1 dc Discharge coefficient []
fpnp1 ef Expansion factor [ ]
fpnp1 mv Fluid mean axial velocity [m/s]
fpnp1 pl Pressure loss [Pa]; for Venturi tubes and Venturi nozzles pl=0
fpnp1 mv Fluid mean axial velocity [m/s]
fpnp1 pl Pressure loss [Pa]; for Venturi tubes and Venturi nozzles pl=0
long errflag Error status
  • Bit 0=1 (0001H) if (0.001 ≥ p[Pa] ≥ 1.0E9), else =0
  • Bit 1=1 (0002H) if (-273.15 ≥ t[degC] ≥ 1000000), else =0
  • Bit 2=1 (0004H) if (dp > 0.25*p or dp<0.00025 Pa), else =0
  • Bit 3=1 (0008H) if (0.0 ≥ d[kg/m^3] ≥ 10000), else =0
  • Bit 4=1 (0010H) if (0.0 ≥ v[Pa*s] ≥ 10.0), else =0
  • Bit 5=1 (0020H) if (0.1 ≥ ie ≥ 2000), else =0
  • Bit 6=1 (0040H) if diameter of orifice or throat or cone (od) out of range, else =0
  • Bit 7=1 (0080H) if pipe diameter (pd) out of range, else =0
  • Bit 8=1 (0100H) if (0.001 ≥ mfr[kg/h] ≥ 1E+9), else =0.
  • Bit 9=1 (0200H) if (0 > ft > 1), else =0.
  • Bit 10=1 (0400H) if (0 > ddt > 9), else =0.
  • Bit 11=1 (0800H) if (0 > ud > 1), else =0.
  • Bit 12=1 (1000H) if beta ratio for the specified device out of range, else =0.
  • Bit 13=1 (2000H) if Reynolds number for the specified device out of range, else =0.
  • All higher order bits are unused

1

"fpnp" is a data type that can be defined as "float" or "double". See the comments at the beginning of the header file below.



Header file "iso5167.h"

// IN CASE OF SINGLE FLOATING POINT NUMBER PRECISION // Include the following directive in "iso5167.h": // #define fpnp float // and replace all scanf() and printf() formats "%lf" by "%f" in "main_iso5167.c" // IN CASE OF DOUBLE FLOATING POINT NUMBER PRECISION // Include the following directive in "iso51167.h": // #define fpnp double // and replace all scanf() and printf() formats "%f" by "%lf" in "main_iso5167.c" #include "stdio.h" #include "math.h" #define fpnp double // declaration of the structure struct iso5167 { // parameters fpnp mfr; // Mass flow rate [kg/h] fpnp rd; // Reynolds number fpnp dc; // Discharge coefficient [] fpnp ef; // Expansion factor [] fpnp br; // Beta ratio [] fpnp mv; // Fluid mean axial velocity [m/s] fpnp pl; // Pressure loss [Pa] short ddt; // Differential device type // 0 -> Orifice with flange tappings // 1 -> Orifice with corner tappings // 2 -> Orifice with D and D/2 tappings // 3 -> Classical Venturi tube with a machined inlet // 4 -> Classical Venturi tube with a rough cast inlet // 5 -> Classical Venturi tube with a rough-welded sheet-iron inlet // 6 -> Long radius nozzle // 7 -> ISA 1932 nozzle // 8 -> Venturi nozzle (ISA inlet) // 9 -> Cone meter short ud; // Position of pressure measurement taps: 0-upstream, 1-downstream short ft; // Type of fluid: 0-gas, 1-liquid fpnp pd; // Pipe diameter [mm] (Pipe diameter range depends on device type) fpnp od; // Orifice or throat or cone diameter [mm] fpnp t; // Temperature [deg C] (-273.15 <= t <= 1000000) fpnp p; // Pressure in [Pa] (0.001 <= p <= 1.0E+9) fpnp dp; // Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) fpnp d; // Fluid density [kg/m3] (0.000001 <= d <= 10000) fpnp v; // Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) fpnp ie; // Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) long errflag; // Error status }; // declaration of the function iso5167() void iso5167(short iCalc, struct iso5167 *);

Example of a main program "main_iso5167.c" in C code calling the function in "iso5167.c"

The following simple example illustrates the call to all four calculation types from a main program. The program prompts for the selection of the calculation type and then for the corresponding input parameters. After execution of the function the program prints the corresponding calculation results on the screen.

/* ******************* */ /* MAIN PROGRAM C-CODE */ /* ******************* */ #include "iso5167.h" void main(void) { struct iso5167 iso, *isox; //'isox' is a pointer to a structure 'iso' short i, j, iCalc; char ch; char *text_ddt = "Differential device\n\ 0 -> Orifice with flange tappings\n\ 1 -> Orifice with corner tappings\n\ 2 -> Orifice with D and D/2 tappings\n\ 3 -> Classical Venturi tube with a machined inlet\n\ 4 -> Classical Venturi tube with a rough cast inlet\n\ 5 -> Classical Venturi tube with a rough-welded sheet-iron inlet\n\ 6 -> Long radius nozzle\n\ 7 -> ISA 1932 nozzle\n\ 8 -> Venturi nozzle (ISA inlet)\n\ 9 -> Cone meter\n\ Type number 0-9: "; char *text_ud = "Upstream = 0 or downstream = 1 pressure tap, type 0 or 1: "; char *text_ft = "Fluid type, 0=gas, 1=liquid: "; char *text_pd = "Pipe diameter [mm]: "; char *text_od = "Orifice or throat or cone diameter [mm]: "; char *text_t = "Temperature [deg C] (-273.15 to 1E6): "; char *text_p = "Pressure [Pa] (0.001 to 1E9): "; char *text_dp = "Differential pressure [Pa] : "; char *text_d = "Density [kg/m3] (0.000001 to 10000: "; char *text_v = "Dynamic viscosity [Pa*s] (0 to 10): "; char *text_ie = "Isentropic exponent (0.1 to 200): "; char *text_mfr = "Mass-flow rate [kg/h]: "; char *text_rd = "Reynolds number: "; char *text_dc = "Discharge coefficient: "; char *text_ef = "Expansion factor: "; char *text_br = "Beta ratio: "; char *text_mv = "Mean axial velocity [m/s]: "; char *text_pl = "Pressure loss [Pa]: "; char *text_ct = "Select calculation\n\ 0 Flow-rate calculation\n\ 1 Differential pressure calculation\n\ 2 Orifice diameter calculation\n\ 3 Pipe diameter calculation\n\ (type number 0-3): "; for (i=0; ; ) { for (j=0; ; ) { // Get input parameters printf("\nINPUT PARAMETERS\n"); printf("%s", text_ct); scanf("%d", &iCalc); if(iCalc>=0 && iCalc<=3) { break; } } if (iCalc == 0) { // Input parameters for flow-rate calculation printf("Input parameters for flow-rate calculation:\n"); printf("%s = ", text_ddt); scanf("%d", &(iso.ddt)); printf("%s = ", text_ud); scanf("%d", &(iso.ud)); printf("%s = ", text_ft); scanf("%d", &(iso.ft)); printf("%s = ", text_pd); scanf("%lf", &(iso.pd)); printf("%s = ", text_od); scanf("%lf", &(iso.od)); printf("%s = ", text_t); scanf("%lf", &(iso.t)); printf("%s = ", text_p); scanf("%lf", &(iso.p)); printf("%s = ", text_dp); scanf("%lf", &(iso.dp)); printf("%s = ", text_d); scanf("%lf", &(iso.d)); printf("%s = ", text_v); scanf("%lf", &(iso.v)); printf("%s = ", text_ie); scanf("%lf", &(iso.ie)); } else if(iCalc == 1) { // Input parameters for differential pressure calculation printf("%s = ", text_ddt); scanf("%d", &(iso.ddt)); printf("%s = ", text_ud); scanf("%d", &(iso.ud)); printf("%s = ", text_ft); scanf("%d", &(iso.ft)); printf("%s = ", text_pd); scanf("%lf", &(iso.pd)); printf("%s = ", text_od); scanf("%lf", &(iso.od)); printf("%s = ", text_t); scanf("%lf", &(iso.t)); printf("%s = ", text_p); scanf("%lf", &(iso.p)); printf("%s = ", text_mfr); scanf("%lf", &(iso.mfr)); printf("%s = ", text_d); scanf("%lf", &(iso.d)); printf("%s = ", text_v); scanf("%lf", &(iso.v)); printf("%s = ", text_ie); scanf("%lf", &(iso.ie)); } else if (iCalc == 2) { // Input parameters for differential device bore diameter calculation printf("%s = ", text_ddt); scanf("%d", &(iso.ddt)); printf("%s = ", text_ud); scanf("%d", &(iso.ud)); printf("%s = ", text_ft); scanf("%d", &(iso.ft)); printf("%s = ", text_pd); scanf("%lf", &(iso.pd)); printf("%s = ", text_t); scanf("%lf", &(iso.t)); printf("%s = ", text_p); scanf("%lf", &(iso.p)); printf("%s = ", text_dp); scanf("%lf", &(iso.dp)); printf("%s = ", text_mfr); scanf("%lf", &(iso.mfr)); printf("%s = ", text_d); scanf("%lf", &(iso.d)); printf("%s = ", text_v); scanf("%lf", &(iso.v)); printf("%s = ", text_ie); scanf("%lf", &(iso.ie)); } else { // Input parameters for pipe diameter calculation printf("%s = ", text_ddt); scanf("%d", &(iso.ddt)); printf("%s = ", text_ud); scanf("%d", &(iso.ud)); printf("%s = ", text_ft); scanf("%d", &(iso.ft)); printf("%s = ", text_br); scanf("%lf", &(iso.br)); printf("%s = ", text_t); scanf("%lf", &(iso.t)); printf("%s = ", text_p); scanf("%lf", &(iso.p)); printf("%s = ", text_dp); scanf("%lf", &(iso.dp)); printf("%s = ", text_mfr); scanf("%lf", &(iso.mfr)); printf("%s = ", text_d); scanf("%lf", &(iso.d)); printf("%s = ", text_v); scanf("%lf", &(iso.v)); printf("%s = ", text_ie); scanf("%lf", &(iso.ie)); } isox = &iso; // Put the address of 'iso' structure into 'isox' iso5167(iCalc, isox); // Call function by passing type of calc. and pointer to structure printf("\n\nR E S U L T S"); // Print error flags as hexadecimal number printf("\nError(Hex) = %x", iso.errflag); if (iCalc == 0) { // Print results printf("\n%s%lf", text_mfr, iso.mfr); printf("\n%s%lf", text_br, iso.br); } else if (iCalc == 1) { // Print results printf("\n%s%lf", text_dp, iso.dp); printf("\n%s%lf", text_br, iso.br); } else if (iCalc == 2) { printf("\n%s%lf", text_od, iso.od); printf("\n%s%lf", text_br, iso.br); } else { printf("\n%s%lf", text_pd, iso.pd); printf("\n%s%lf", text_od, iso.od); } printf("\n%s%lf", text_rd, iso.rd); printf("\n%s%lf", text_dc, iso.dc); printf("\n%s%lf", text_ef, iso.ef); printf("\n%s%lf", text_mv, iso.mv); printf("\n%s%lf", text_pl, iso.pl); 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 */ /* ****************************** */