iso5167.c - Instructions for use

Revision: April 25, 2005

 

E-mail: ivan.maric@felib.com

 

iso5167.c  is the C source code implementation of the International standards:

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

Part 1: General principles and requirements

Part 2: Orifice plates

Part 3: Nozzles and Venturi nozzles

Part 4: Venturi tubes

 

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

The following is a brief description of the functions and the corresponding input/output parameters given in a source code .

 

/* ISO5167 ROUTINE */

/* Implementation of ISO5167 calculations (ISO-5167-1 to ISO-5167-4/2003) */

/* Rev. April 25, 2005

 

/* Calculation of flow-rate [kg/h], differential pressure [Pa], orifice diameter [mm] */

/* and pipe diameter [mm], in accordance with ISO5167,2003 */

 

/* Functions: */

/* =========================================================================================== */

/* 1) void calculateFlowRate()             - calculates mass flow rate, Reynolds number, */

/*                                           discharge coefficient, expansion factor, beta ratio */

/*                                           and sets and returns error status (see ***) */

/* 2) void calculateDifferentialPressure() - calculates differential pressure, Reynolds number, */

/*                                           discharge coefficient, expansion factor, beta ratio */

/*                                           and sets and returns error status (see ***) */

/* 3) void calculateOrificeDiameter()      - calculates orifice diameter, Reynolds number, */

/*                                           discharge coefficient, expansion factor, beta ratio */

/*                                           and sets and returns error status (see ***) */

/* 4) void calculatePipeDiameter()         - calculates pipe diameter, orifice diameter, Reynolds */

/*                                           number, discharge coefficient, expansion factor */

/*                                           and sets and returns error status (see ***) */

/* =========================================================================================== */

 

/* Read/write input parameters common to all four functions above: */

/* =========================================================================================== */

/* float p         - absolute pressure p[Pa] (0.001 <= p <= 1.0E+9) */

/* float t         - temperature t[degC] (-273.15 <= t <= 1000000) */

/* short ft        - type of fluid ft(ft=0, gas; ft=1, liquid) */

/* float d         - fluid density d[kg/m^3] (0.000001 <= d <= 10000) */

/* float v         - dynamic viscosity of the fluid v[Pa*s] (0.0 <= v <= 10.0) */

/* float ie        - isentropic exponent ie[] (0.1 <= ie <= 200 for gases, 0 for liquids) */

/* short ddt       - differential device type (0 >= ddt >= 8) */

/*                            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) */

/* short ud        - upstream/downstream pressure measurement */

/*                     ud = 0 -> upstream */

/*                     ud = 1 -> downstream */

/* =========================================================================================== */

 

/* Read/write parameters that can be input parameters and results depending on the function: */

/* =========================================================================================== */

/* float dp        - differential pressure dp[Pa]((p-dp)/p >= 0.75), */

/*                     input parameter to functions 1), 3) and 4) and output */

/*                     result from function 2) (see functions above) */

/* float od        - orifice diameter od[mm], input parameter to functions */

/*                     1) and 2) and output result from functions 3) and 4) */

/*                     (see functions above) */

/*                     Restrictions on orifice diameter 'od' depending on */

/*                     differential device type 'ddt' */

/*                       ddt=0, od >= 12.5mm */

/*                       ddt=1, od >= 12.5mm */

/*                       ddt=2, od >= 12.5mm */

/*                       ddt=3, od >= 30.0mm */

/*                       ddt=4, od >= 20.0mm */

/*                       ddt=5, od >= 80.0mm */

/*                       ddt=6, od >= 10.0mm */

/*                       ddt=7, od >= 15.0mm */

/*                       ddt=8, od >= 50.0mm */

/* float br        - orifice to pipe diameter ratio br[], input parameter to */

/*                     function 3) and output result from functions 1), 2) and 4) */

/*                     (see functions above) */

/* float pd        - pipe diameter pd[mm], input parameter to functions */

/*                     1), 2) and 3) and output result from function 4) */

/*                     (see functions above) */

/*                     Restrictions on pipe diameter 'od' depending 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 */

/* float mfr       - mass flow-rate mfr[kg/h], input parameter to functions */

/*                     2), 3) and 4) and output result from function 1) */

/*                     (see functions above)(0.001 <= mfr[kg/h] <= 1E+9) */

/* =========================================================================================== */

/*

/* The output parameters (results) common to all four functions above */

/* =========================================================================================== */

/* float rd        - Reynolds number [] */

/* float dc        - Discharge coefficient[] */

/* float ef        - Expansion factor ] */

/* float mv        - Fluid mean axial velocity [m/s] */

/* float pl        - Pressure loss [Pa]; For Venturi tubes and Venturi nozzles is set to zero. */

/* long errflag    - Error status (see ***) */

/* =========================================================================================== */

 

/* *** */

/* long errflag represents error status in the following way:  */

/* =========================================================================================== */

/* Bit 0   =1 (000001H) if (0.001 >= p[Pa] >= 1.0E9), otherwise =0. */

/* Bit 1   =1 (000002H) if (-273.15 >= t[degC] >= 1000000), otherwise =0. */

/* Bit 2   =1 (000004H) if (dp > 0.25*p or dp<0.00025 Pa), otherwise =0. */

/* Bit 3   =1 (000008H) if (0.0 >= d[kg/m^3] >= 10000), otherwise =0. */

/* Bit 4   =1 (000010H) if (0.0 >= v[Pa*s] >= 10.0), otherwise =0. */

/* Bit 5   =1 (000020H) if (0.1 >= ie >= 2000), otherwise =0. */

/* Bit 6   =1 (000040H) if orifice diameter (od) out of range, otherwise =0. */

/* Bit 7   =1 (000080H) if pipe diameter (pd) out of range, otherwise =0. */

/* Bit 8   =1 (000100H) if (0.001 >= mfr[kg/h] >= 1E+9), otherwise =0. */

/* Bit 9   =1 (000200H) if (0 > ft > 1), otherwise =0. */

/* Bit 10  =1 (000400H) if (0 > ddt > 8), otherwise =0. */

/* Bit 11  =1 (000800H) if (0 > ud > 1), otherwise =0. */

/* Bit 12  =1 (001000H) if beta ratio for the specified device out of range, otherwise =0. */

/* Bit 13  =1 (002000H) if Reynolds number for the specified device out of range, otherwise =0. */

/* All other bits are unused */

/* =========================================================================================== */

 

 

 

Functions

 

The following is the definition of the functions:

 

/* declaration of the function CalculateFlowRate */

void CalculateFlowRate(

/* output parameters */

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

     float *mfr,                                /* Mass flow rate [kg/h] */

     float *rd,                                        /* Reynolds number */

     float *dc,                                        /* Discharge coefficient [] */

     float *ef,                                        /* Expansion factor [] */

     float *br,                                        /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float od,       /* Orifice diameter [mm] (Orifice diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculateDifferentialPressure */

void CalculateDifferentialPressure(

/* output parameters */

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

     float *dp,                                        /* Differential pressure in [Pa] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *br,                                 /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float od,       /* Orifice diameter [mm] (Orifice diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculateOrificeDiameter */

void CalculateOrificeDiameter(

/* output parameters */

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

     float *od,                                 /* Orifice diameter [mm] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *br,                                 /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculatePipeDiameter */

void CalculatePipeDiameter(

/* output parameters */

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

     float *pd,                                 /* Pipe diameter [mm] */

     float *od,                                 /* Orifice diameter [mm] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float br,       /* Orifice to pipe diameter ratio [] */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);


Example of a main program in C code calling the iso5167 functions

 

 

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

 

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

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

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

 

#include "stdio.h"

#include "conio.h"

 

/* declaration of the function CalculateFlowRate */

void CalculateFlowRate(

/* output parameters */

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

     float *mfr,                                /* Mass flow rate [kg/h] */

     float *rd,                                        /* Reynolds number */

     float *dc,                                        /* Discharge coefficient [] */

     float *ef,                                        /* Expansion factor [] */

     float *br,                                        /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float od,       /* Orifice diameter [mm] (Orifice diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculateDifferentialPressure */

void CalculateDifferentialPressure(

/* output parameters */

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

     float *dp,                                        /* Differential pressure in [Pa] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *br,                                 /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float od,       /* Orifice diameter [mm] (Orifice diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculateOrificeDiameter */

void CalculateOrificeDiameter(

/* output parameters */

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

     float *od,                                 /* Orifice diameter [mm] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *br,                                 /* Orifice to pipe diameter ratio [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float pd,             /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

/* declaration of the function CalculatePipeDiameter */

void CalculatePipeDiameter(

/* output parameters */

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

     float *pd,                                 /* Pipe diameter [mm] */

     float *od,                                 /* Orifice diameter [mm] */

     float *rd,                                 /* Reynolds number */

     float *dc,                          /* Discharge coefficient [] */

     float *ef,                          /* Expansion factor [] */

     float *mv,                                        /* Fluid mean axial velocity [m/s] */

     float *pl,                                        /* Pressure loss [Pa] */

/* input parameters */

     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) */

     short ud,             /* Position of pressure measurement taps: 0-upstream, 1-downstream */

     short ft,             /* Type of fluid: 0-gas, 1-liquid */

     float br,       /* Orifice to pipe diameter ratio [] */

     float t,        /* Temperature [deg C] (-273.15 <= t <= 1000000) */

     float p,        /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

     float dp,             /* Differential pressure in [Pa] dp[Pa] (dp <= 0.25*p_upstream) */

     float mfr,      /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

     float d,        /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

     float v,        /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

     float ie        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

);

 

void main(void)

{

   unsigned short int j, itype;

   char ch;

 

/* Input and output data */

   unsigned long int error;

   float dp;        /* Differential pressure in [Pa] */

   float rd;        /* Reynolds number */

   float dc;        /* Discharge coefficient [] */

   float ef;        /* Expansion factor [] */

   float br;        /* Orifice to pipe diameter ratio [] */

   short ddt;       /* Differential device type */

   short ud;        /* Position of pressure measurement taps: 0-upstream, 1-downstream */

   short ft;        /* Type of fluid: 0-gas, 1-liquid */

   float pd;        /* Pipe diameter [mm] (Pipe diameter range depends on device type) */

   float od;        /* Orifice diameter [mm] (Orifice diameter range depends on device type) */

   float t;         /* Temperature [deg C] (-273.15 <= t <= 1000000) */

   float p;         /* Pressure in [Pa] (0.001 <= p <= 1.0E+9) */

   float mfr;       /* Mass flow rate [kg/h] (0.001 <= mfr <= 1E+9)*/

   float d;         /* Fluid density  [kg/m3] (0.000001 <= d <= 10000) */

   float v;         /* Fluid dynamic viscosity [Pa*s] (0.0 <= v <= 10.0) */

   float ie;        /* Isentropic exponent [] (0.1 <= ie <= 200 for gases, 0 for liquids) */

   float mv;        /* Mean axial velocity [m/s]) */

   float pl;        /* Pressure loss [Pa] */

 

 

   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\

Type number 0-8: ";

   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 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 = "Orifice to pipe diameter ratio: ";

   char *text_mv = "Mean axial velocity [m/s]: ";

   char *text_pl = "Pressure loss [Pa]: ";

 

 

   for (j=0; ; ) {

 

/* Get input parameters */

       printf("\nINPUT PARAMETERS\n");

       printf("%s", "Select calculation\n\

1 Flow-rate calculation\n\

2 Differential pressure calculation\n\

3 Orifice diameter calculation\n\

4 Pipe diameter calculation\n\

(type number 1-4): ");

       scanf("%d", &itype);

       if (itype == 1) {

              /* Input parameters for flow-rate calculation */

             printf("%s = ", text_ddt); scanf("%d", &ddt);

             printf("%s = ", text_ud); scanf("%d", &ud);

             printf("%s = ", text_ft); scanf("%d", &ft);

             printf("%s = ", text_pd); scanf("%f", &pd);

             printf("%s = ", text_od); scanf("%f", &od);

             printf("%s = ", text_t); scanf("%f", &t);

             printf("%s = ", text_p); scanf("%f", &p);

             printf("%s = ", text_dp); scanf("%f", &dp);

             printf("%s = ", text_d); scanf("%f", &d);

             printf("%s = ", text_v); scanf("%f", &v);

             printf("%s = ", text_ie); scanf("%f", &ie);

              /* Print input parameters */

              printf("\nFlow-rate calculation");

              printf("\n%s%d", text_ddt, ddt);

              printf("\n%s%d", text_ud, ud);

              printf("\n%s%d", text_ft, ft);

              printf("\n%s%f", text_pd, pd);

              printf("\n%s%f", text_od, od);

              printf("\n%s%f", text_t, t);

              printf("\n%s%f", text_p, p);

              printf("\n%s%f", text_dp, dp);

              printf("\n%s%f", text_d, d);

              printf("\n%s%f", text_v, v);

              printf("\n%s%f", text_ie, ie);

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

              /* call CalculateFlowRate() routine */

              CalculateFlowRate(&error, &mfr, &rd, &dc, &ef, &br, &mv, &pl, ddt, ud, ft, pd, od, t, p, dp, d, v, ie);

              /* Print error flags as hexadecimal number */

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

              /* Print results */

              printf("\n%s%f", text_mfr, mfr);

              printf("\n%s%f", text_rd, rd);

              printf("\n%s%f", text_dc, dc);

              printf("\n%s%f", text_ef, ef);

              printf("\n%s%f", text_br, br);

              printf("\n%s%f", text_mv, mv);

              printf("\n%s%f", text_pl, pl);

       }

       else if (itype == 2) {

              /* Input parameters for differential pressure calculation */

             printf("%s = ", text_ddt); scanf("%d", &ddt);

             printf("%s = ", text_ud); scanf("%d", &ud);

             printf("%s = ", text_ft); scanf("%d", &ft);

             printf("%s = ", text_pd); scanf("%f", &pd);

             printf("%s = ", text_od); scanf("%f", &od);

             printf("%s = ", text_t); scanf("%f", &t);

             printf("%s = ", text_p); scanf("%f", &p);

             printf("%s = ", text_mfr); scanf("%f", &mfr);

             printf("%s = ", text_d); scanf("%f", &d);

             printf("%s = ", text_v); scanf("%f", &v);

             printf("%s = ", text_ie); scanf("%f", &ie);

              /* Print input parameters */

              printf("\nDifferential pressure calculation");

              printf("\n%s%d", text_ddt, ddt);

              printf("\n%s%d", text_ud, ud);

              printf("\n%s%d", text_ft, ft);

              printf("\n%s%f", text_pd, pd);

              printf("\n%s%f", text_od, od);

              printf("\n%s%f", text_t, t);

              printf("\n%s%f", text_p, p);

              printf("\n%s%f", text_mfr, mfr);

              printf("\n%s%f", text_d, d);

              printf("\n%s%f", text_v, v);

              printf("\n%s%f", text_ie, ie);

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

              /* call CalculateDifferentialPressure() routine */

              CalculateDifferentialPressure(&error, &dp, &rd, &dc, &ef, &br, &mv, &pl, ddt, ud, ft, pd, od, t, p, mfr, d, v, ie);

              /* Print error flags as hexadecimal number */

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

              /* Print results */

              printf("\n%s%f", text_dp, dp);

              printf("\n%s%f", text_rd, rd);

              printf("\n%s%f", text_dc, dc);

              printf("\n%s%f", text_ef, ef);

              printf("\n%s%f", text_br, br);

              printf("\n%s%f", text_mv, mv);

              printf("\n%s%f", text_pl, pl);

       }

       else if (itype == 3) {

              /* Input parameters for differential device bore diameter calculation */

             printf("%s = ", text_ddt); scanf("%d", &ddt);

             printf("%s = ", text_ud); scanf("%d", &ud);

             printf("%s = ", text_ft); scanf("%d", &ft);

             printf("%s = ", text_pd); scanf("%f", &pd);

             printf("%s = ", text_t); scanf("%f", &t);

             printf("%s = ", text_p); scanf("%f", &p);

             printf("%s = ", text_dp); scanf("%f", &dp);

             printf("%s = ", text_mfr); scanf("%f", &mfr);

             printf("%s = ", text_d); scanf("%f", &d);

             printf("%s = ", text_v); scanf("%f", &v);

             printf("%s = ", text_ie); scanf("%f", &ie);

              /* Print input parameters */

              printf("\nOrifice diameter calculation");

              printf("\n%s%d", text_ddt, ddt);

              printf("\n%s%d", text_ud, ud);

              printf("\n%s%d", text_ft, ft);

              printf("\n%s%f", text_pd, pd);

              printf("\n%s%f", text_t, t);

              printf("\n%s%f", text_p, p);

              printf("\n%s%f", text_dp, dp);

              printf("\n%s%f", text_mfr, mfr);

              printf("\n%s%f", text_d, d);

              printf("\n%s%f", text_v, v);

              printf("\n%s%f", text_ie, ie);

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

              /* call CalculateOrificeDiameter() routine */

              CalculateOrificeDiameter(&error, &od, &rd, &dc, &ef, &br, &mv, &pl, ddt, ud, ft, pd, t, p, dp, mfr, d, v, ie);

              /* Print error flags as hexadecimal number */

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

              /* Print results */

              printf("\n%s%f", text_od, od);

              printf("\n%s%f", text_rd, rd);

              printf("\n%s%f", text_dc, dc);

              printf("\n%s%f", text_ef, ef);

              printf("\n%s%f", text_br, br);

              printf("\n%s%f", text_mv, mv);

              printf("\n%s%f", text_pl, pl);

       }

       else {

              /* Input parameters for pipe diameter calculation */

             printf("%s = ", text_ddt); scanf("%d", &ddt);

             printf("%s = ", text_ud); scanf("%d", &ud);

             printf("%s = ", text_ft); scanf("%d", &ft);

             printf("%s = ", text_br); scanf("%f", &br);

             printf("%s = ", text_t); scanf("%f", &t);

             printf("%s = ", text_p); scanf("%f", &p);

             printf("%s = ", text_dp); scanf("%f", &dp);

             printf("%s = ", text_mfr); scanf("%f", &mfr);

             printf("%s = ", text_d); scanf("%f", &d);

             printf("%s = ", text_v); scanf("%f", &v);

             printf("%s = ", text_ie); scanf("%f", &ie);

              /* Print input parameters */

              printf("\nPipe diameter calculation");

              printf("\n%s%d", text_ddt, ddt);

              printf("\n%s%d", text_ud, ud);

             printf("\n%s%d", text_ft, ft);

              printf("\n%s%f", text_br, br);

              printf("\n%s%f", text_t, t);

              printf("\n%s%f", text_p, p);

              printf("\n%s%f", text_dp, dp);

              printf("\n%s%f", text_mfr, mfr);

              printf("\n%s%f", text_d, d);

              printf("\n%s%f", text_v, v);

              printf("\n%s%f", text_ie, ie);

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

              /* call CalculatePipeDiameter() routine */

              CalculatePipeDiameter(&error, &pd, &od, &rd, &dc, &ef, &mv, &pl, ddt, ud, ft, br, t, p, dp, mfr, d, v, ie);

              /* Print error flags as hexadecimal number */

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

              /* Print results */

              printf("\n%s%f", text_pd, pd);

              printf("\n%s%f", text_od, od);

              printf("\n%s%f", text_rd, rd);

              printf("\n%s%f", text_dc, dc);

              printf("\n%s%f", text_ef, ef);

              printf("\n%s%f", text_mv, mv);

              printf("\n%s%f", text_pl, pl);

       }

       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 */

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