program shunt; {This program calculates the physiological blood shunts. See the display heading procedure for details. By C. S. Tritt 02/05/86} {$I bldcalc2.pas} {$I iolib.pas} type entmeas = string[27]; const po2in: real = 40.0; po2out: real = 95.0; po2eq: real = 104.0; pco2in: real = 45.0; pco2out: real = 40.0; pco2eq: real = 40.0; phin: real = 7.36; phout: real = 7.40; phi: real = 7.46; phs: real = -0.2884; bemean: real = 0.0; hct: real = 40.0; hb: real = 15.0; temp: real = 37.0; enttext : entmeas = 'Enter new value or RETURN: '; phiint : real = 7.367; {Intercept of phi vs. be plot} phislope : real = 0.0132; {Slope of phi vs. be plot} var pkco2in, pkco2out, pkco2eq, bicarbin, bicarbout, bicarbeq, bein, beout, beeq, cpo2in, cpo2out, cpo2eq, o2satin, o2satout, o2sateq, o2cnin, o2cnout, o2cneq, co2cnin, co2cnout, co2cneq, hbcor: real; pheq, shunto2, shuntco2, shuntbar: real; phicalc, becalc, clcfgin, clcfgout, clcfgeq, goodio, pherror, phcalc: boolean; co2mthno, j: integer; parm: parmlist; method: methray; species: strof14; co2meth, phmeth, bemeth, rslttype, continue, tryagain, ritefile, dummy: char; desttag: text; procedure display_heading; begin clrscr; writeln; writeln('Chuck''s Shunt Calculator'); writeln; writeln('This program calculates the physiological blood shunt through a device or'); writeln('the natural lungs. It uses the equations of Kelman (1967), Lutz (1975),'); writeln('Gabel (1981) and Loeppky (1983). Shunt calculations are most accurate when'); writeln('there are large changes in the basis gas concentration in the blood as it'); writeln('passes through the device or lungs. To retain a parameter value, enter a'); writeln('RETURN in response to the prompt. Constants used in the calculation of'); writeln('percent hemoglobin saturation by the method of Lutz should be in a ASCII'); writeln('text file. The first line in the file should contain only the species name'); writeln('(maximum length 14 letters). The second line of the file should contain the'); writeln('parameters separated by single spaces and in the following order: Bohr'); writeln('factor, a, b, k1, k2, k3, k4, k5, k6. Standard files of Lutz parameters'); writeln('exist and have names of the species. This program must calculate the'); writeln; wait; clrscr; writeln; writeln('pH of the blood equilibrated with the gas phase. To do this calculation,'); writeln('the program can use a linear relationship between pH and ln(PCO2/42.5). To'); writeln('prevent problems at PCO2''s near zero, a maximum pH based on the base excess'); writeln('relation of Thews (1971) is used whenever the calculated pH exceeds this maxi-'); writeln('mum pH. The program contains pH-ln(PCO2/42.5) slope and intercept data for'); writeln('swine blood. An alternate approach that can be used by the program is based'); writeln('on the assumption of constant base excess through the device. The user is'); writeln('asked to choose a method. The program will calculate the base excess if one'); writeln('is not entered.'); writeln; writeln('It is the responsiblity of the user to determine if this program is suitable'); writeln('for a particular application. This program has been placed in the public'); writeln('by the author and may be copied. The financial support of the Department of'); writeln('Anesthesology, The Ohio State University is greatfully acknowledged.'); writeln; writeln('Version 2.0'); writeln('By C. S. Tritt'); writeln('Feb. 4, 1986'); writeln; end; procedure getgases(var po2, pco2: real; entstrng: entmeas; var device: text); {This procedure gets blood gases} begin putreal(po2, 5, 1, 'PO2 in mmHg', device); getreal(po2, entstrng); echoreal(po2, 5, 1); writeln; putreal(pco2, 6, 2, 'PCO2 in mmHg', device); getreal(pco2, entstrng); echoreal(pco2, 6, 2); writeln; end; begin {mainline} method[1] := 'Lutz'; method[2] := 'Kelman'; method[3] := 'Loeppky'; display_heading; wait; clrscr; phicalc := false; becalc := false; getlutz(species, parm); writeln; getco2m(co2meth, co2mthno, method); getroute(ritefile, desttag); {Get basis for calculations} repeat writeln('Enter number of calculation basis to be used.'); writeln; writeln(' 1 - Oxygen'); writeln(' 2 - Carbon Dioxide'); writeln(' 3 - Both'); writeln; read(kbd, rslttype); until (rslttype = '1') or (rslttype = '2') or (rslttype = '3'); {Get pH - PCO2 relationship} repeat write('Use constant base excess pH - PCO2 relationship? (y or n) '); read(kbd, phmeth); writeln; writeln; phmeth := upcase(phmeth); if phmeth = 'Y' then phcalc := true else begin phcalc := false; write('Use swine pH - ln(PCO2/42.5) parameters? (y or n) '); read(kbd, phmeth); writeln; phmeth := upcase(phmeth); case phmeth of 'N': begin writeln; putreal(phs, 6, 3, 'slope', con); getreal(phs, enttext); echoreal(phs, 6, 3); writeln; putreal(phi, 6, 3, 'intercept', con); getreal(phi, enttext); echoreal(phi, 6, 3); end; 'Y': phicalc := true; end; end; until (phmeth = 'N') or (phmeth = 'Y'); {Get B.E. data} repeat writeln; write('Use calculated base excess? (y or n) '); read(kbd, bemeth); writeln; writeln; bemeth := upcase(bemeth); case bemeth of 'N': begin putreal(bemean, 5, 2, 'base excess in mEq/l', con); getreal(bemean, enttext); echoreal(bemean, 5, 2); writeln; end; 'Y': becalc := true; end; until (bemeth = 'N') or (bemeth = 'Y'); wait; {Get globel conditions from user} repeat {outer loop} {Get global conditions} clrscr; writeln('Enter overall conditions:'); writeln; putreal(hct, 4, 1, 'haematocrit in percent', con); getreal(hct, enttext); echoreal(hct, 4, 1); writeln; putreal(hb, 5, 2, 'hemoglobin in gm/100 ml', con); getreal(hb, enttext); echoreal(hb, 5, 2); hbcor := hb; writeln; putreal(temp, 4, 1, 'temperature in C', con); getreal(temp, enttext); echoreal(temp, 4, 1); writeln; wait; clrscr; repeat {inner loop} {Get particular conditions} clrscr; writeln; writeln('Enter blood inlet conditions (Mixed venous):'); writeln; getgases(po2in, pco2in, enttext, con); putreal(phin, 5, 3, 'pH', con); getreal(phin, enttext); echoreal(phin, 5, 3); writeln; wait; clrscr; writeln; writeln('Enter outlet conditions (Arterial):'); writeln; getgases(po2out, pco2out, enttext, con); putreal(phout, 5, 3, 'pH', con); getreal(phout, enttext); echoreal(phout, 5, 3); writeln; wait; clrscr; writeln; writeln('Enter equilibrating gas (End tidal):'); writeln; getgases(po2eq, pco2eq, enttext, con); writeln; wait; clrscr; writeln; {Do calculations} clcfgin := false; bldcon(o2cnin, co2cnin, bein, po2in, pco2in, phin, temp, hct, hb, hbcor, co2mthno, parm, clcfgin); clcfgout := false; bldcon(o2cnout, co2cnout, beout, po2out, pco2out, phout, temp, hct, hb, hbcor, co2mthno, parm, clcfgout); if becalc then bemean := (bein + beout) / 2.0; if phicalc then phi := phiint + phislope * bemean; pheq := fphcalc2(pco2eq, phs, phi, bemean, temp, phcalc, pherror); bldcon(o2cneq, co2cneq, beeq, po2eq, pco2eq, pheq, temp, hct, hb, hbcor, co2mthno, parm, clcfgeq); shunto2 := fshunt(o2cnin, o2cnout, o2cneq); if shunto2 < 0.0 then begin shunto2 := 0.0; clcfgeq := true; end else if shunto2 > 1.0 then begin shunto2 := 1.0; clcfgeq := true; end; shuntco2 := fshunt(co2cnin, co2cnout, co2cneq); if shuntco2 < 0.0 then begin shuntco2 := 0.0; clcfgeq := true; end else if shunto2 > 1.0 then begin shuntco2 := 1.0; clcfgeq := true; end; shuntbar := (shunto2 + shuntco2) / 2.0; {Write output file} clrscr; writeln(desttag); putstring(method[co2mthno], 'CO2 content method: ', desttag); putstring(species, 'Species: ', desttag); if phcalc then writeln(desttag, 'Constant base excess assumed.') else begin writeln(desttag, 'Linear pH - ln(PCO2/42.5) relation assumed, with'); writeln(desttag, 'slope = ', phs:6:3, ' and intercept = ', phi:5:3,'.'); end; writeln(desttag); putreal(hct, 4, 1, 'average haematocrit in percent', desttag); putreal(hb, 5, 2, 'average hemoglobin concentration in gm/100 ml', desttag); putreal(temp, 4, 1, 'body temperature', desttag); writeln(desttag); putreal(po2in, 5, 1, 'inlet PO2 in mm Hg', desttag); putreal(pco2in, 6, 2, 'inlet PCO2 in mm Hg', desttag); putreal(phin, 5, 3, 'inlet pH', desttag); putreal(bein, 4, 1, 'inlet B.E.', desttag); writeln(desttag); putreal(po2out, 5, 1, 'outlet PO2 in mm Hg', desttag); putreal(pco2out, 6, 2, 'outlet PCO2 in mm Hg', desttag); putreal(phout, 5, 3, 'outlet pH', desttag); putreal(beout, 4, 1, 'outlet B.E.', desttag); if ritefile = 'S' then begin writeln; wait; clrscr; end; writeln(desttag); putreal(po2eq, 5, 1, 'equilibrium PO2 in mm Hg', desttag); putreal(pco2eq, 6, 2, 'equilibrium PCO2 in mm Hg', desttag); putreal(pheq, 5, 3, 'equilibrium pH', desttag); putreal(beeq, 5, 2, 'equilibrium base excess in mEq/l', desttag); putreal(o2cneq, 4, 1, 'equilibrium O2 content in volume percent', desttag); putreal(co2cneq, 4, 1, 'equilibrium CO2 content in volume percent', desttag); writeln(desttag); case rslttype of '1' : putreal(shunto2, 5, 3, 'shunt fraction based on O2', desttag); '2' : putreal(shuntco2, 5, 3, 'shunt fraction based on CO2', desttag); '3' : begin putreal(shunto2, 5, 3, 'shunt fraction based on O2', desttag); putreal(shuntco2, 5, 3, 'shunt fraction based on CO2', desttag); putreal(shuntbar, 5, 3, 'average shunt fraction', desttag); end; end; writeln(desttag); if clcfgin then writeln(desttag, 'Possible error in blood inlet'+ ' calculations.'); if clcfgout then writeln(desttag, 'Possible error in blood outlet'+ ' calculations.'); if pherror then writeln(desttag, 'Possible error in pH calculations.'); if clcfgeq then writeln(desttag, 'Possible error in equilibrium blood'+ ' calculations.'); writeln(desttag); write('Do you wish to continue? (y or n) '); read(kbd, continue); writeln; continue := upcase(continue); if continue <> 'N' then begin writeln; write('Do you wish change overall conditions? (y or n) '); read(kbd, tryagain); writeln; tryagain := upcase(tryagain); end else tryagain := 'N'; until (continue = 'N') or ((continue = 'Y') and (tryagain = 'Y')); until continue = 'N'; {$I-} close(desttag); iocheck(goodio, 'Problem closing output file.'); {$I+} end.