! ! HDX.B4S: Hardy-Cross Pipe Network Analysis ! ! Include files ! {BL:[101,5]TRUTH.B4S} {BL:[101,5]FCSERRCOM.B4S} ! {HDXDEFMAP.B4S} ! ! *************** GCl parameter input ******************* ! iterations%, debug% = .false% not.finished%, more.data% = .true% ! rwatitle$ = chr$(27%) + "[2J" + chr$(27%) + "[3;1H" + & " Richard Wittenoom and Associates Pty Ltd" + CR + LF + LF + & " HARDY CROSS PIPE NETWORK ANALYSIS" + CR + LF + LF + LF + LF ! frst% = .true% ! WHILE not.finished% ! print "starting n.f. loop" WHILE more.data% ! print "starting m.d. loop" ! IF frst% & THEN prompt$ = rwatitle$ + "HDX>" & \ frst% = .false% & ELSE prompt$ = LF + LF + CR + "HDX>" ! CALL GCL.(prompt$,LEN(prompt$), command.buffer$, .cmd.line.siz%, len.got%, EG%, EF%, ED%) command$ = EDIT$(left$(command.buffer$, len.got%), 32%+128%) fields% = .max.args% CALL READTF (command$, 2%, 0%, 0%, field$(), "", fields%) ! CALL HDXSET(field$(), command$, title$, outfile$, err$) ! print CR + LF + command$ IF echo% do% = fn.help% IF help% GOTO 32000 IF (NOT (not.finished%)) ! bomb directly if req. ! ! print "before the first NEXT - flow%: "; flow% NEXT ! ! print "after the first NEXT " ! loops.fil$ = outfile$ + ".WK2" out.fil$ = outfile$ + ".OUT" INPUT "log file "; log.fil$ IF debug% > 0% ! outfile$ + ".LOG" ! CALL OPEN. (loops.fil$, "W", .loops.chan%, .loops.buf.siz%) CALL OPEN. (out.fil$, "W", .tf.out.chan%, 0%) CALL OPEN. (log.fil$, "W", .log.chan%, 0%) IF debug% > 0% ! do% = fn.dump.loopfile% IF debug% > 4% ! ! ******************* main work area ******************* ! ! initial initialisation ! LET current.loop% = 1% LET sigma.Hl.on.Q = 0 LET sigma.Hl = 0 ! ! main iteration loop ! ! print "num.its "; num.its% FOR iteration% = 1% to num.its% ! print "iteration "; iteration% offset% = (iteration% - 1%) * 3% ! IF debug% > 2% & THEN outrec$ = "iteration% =" + num1$(iteration%) + " offset% =" + num1$(offset%) + CR + LF & \ CALL PRINT.(.log.chan%, outrec$) ! first% = .true% ! FOR fl.ow% = 1% to flow% ! CALL GET. (.flows.chan%, flowbuf$, fl.ow%) IF first% & THEN current.loop% = loop% & \ first% = .false% ! IF loop% = current.loop% & THEN do% = fn.flow% & ELSE do% = fn.loop% & \ current.loop% = loop% & \ do% = fn.flow% ! NEXT fl.ow% ! do% = fn.loop% do% = fn.apply.delta.qs% ! NEXT iteration% ! do% = fn.output% ! do% = fn.dump.array% IF debug% > 1% ! ! print "leaving the main loop" more.data% = .true% ! NEXT ! ! ********************** FUNCTIONS ************************* ! ! Variables are: ! Q: itrn.val(offset%) ! hl (m): itrn.val(offset% + 1%) ! dQ: itrn.val(offset% + 2%) ! next Q: itrn.val(offset% + 3%) ! ! ************** process the current flow record ************ ! DEF fn.flow% ! do% = fn.calculate.pipe% sigma.hl.on.Q = sigma.hl.on.Q + hl.on.Q ! accumulate sigma.hl = sigma.hl + itrn.val(offset% + 1%) ! (hl) CALL PUT. (.flows.chan%, flowbuf$, fl.ow%) ! FNEND ! ! ***************** process the preceding loop *************** ! DEF fn.loop% ! IF sigma.hl.on.q = 0 & THEN delta.Q = 0 & ELSE delta.Q = -(sigma.hl / (1.85 * sigma.hl.on.Q)) ! IF debug% > 2% & THEN outrec$ = "loop: " + num1$(loop%) + " sigma h: " + num1$(sigma.hl) & + " sigma h/q: " + num1$(sigma.hl.on.q) & + " delta q: " + num1$(delta.q) + CR + LF & \ CALL PRINT.(.log.chan%, outrec$) ! CALL PUT. (.loops.chan%, loopbuf$, current.loop%) current.loop% = loop% IF err1% <> .eof% sigma.hl = 0 sigma.hl.on.Q = 0 ! initialise accumulators ! FNEND ! ! ***************** calculate pipe values ********************* ! DEF fn.calculate.pipe% ! K = ((1/(PI * (diam^2)/4.0E6)) / (0.849 * pipe.coeff * ((diam/4.0E3)^0.63)))^1.85 q = abs(itrn.val(offset%)) ! set up to avoid negative values q.sign = sgn(itrn.val(offset%)) ! in arguments in exp function itrn.val(offset% + 1%) = K * q.sign * q^1.85 * length ! head ! IF q = 0 & THEN hl.on.q = 0 & ELSE hl.on.q = itrn.val(offset% + 1%) / itrn.val(offset%) ! IF debug% > 3% & THEN outrec$ = "loop: " + num1$(loop%) + " pipe: " + num1$(pipe%) + " q: " & + num1$(itrn.val(offset%)) + " h: " + num1$(itrn.val(offset% + 1%)) & \ CALL PRINT.(.log.chan%, outrec$) ! FNEND ! ! ************* apply flow adjustments to each loop *********** ! DEF fn.apply.delta.Qs% ! FOR I% = 1% to flow% CALL GET. (.flows.chan%, flowbuf$, I%) CALL GET. (.loops.chan%, loopbuf$, loop%) this.loop.delta.q = delta.q ! IF other.loop% = 0% & THEN other.loop.delta.q = 0 & ELSE CALL GET.(.loops.chan%, loopbuf$, other.loop%) & \ other.loop.delta.q = delta.q ! itrn.val(offset% + 2%) = this.loop.delta.q - other.loop.delta.q itrn.val(offset% + 3%) = itrn.val(offset%) + itrn.val(offset% + 2%) ! a$ = "###" z$ = "##.##########" IF debug% > 0% & THEN outrec$ = "pipe: " + format$(pipe%, a$) & + " q: " + format$(itrn.val(offset%), z$) & + " delta q (this): " + format$(this.loop.delta.q, z$) & + " delta q (other): " + format$(other.loop.delta.q, z$) & + " NEXT Q: " + format$(itrn.val(offset% + 3%), z$) & \ CALL PRINT.(.log.chan%, outrec$) ! CALL PUT.(.flows.chan%, flowbuf$, I%) ! NEXT I% ! FNEND ! ! *************** final Q, H and output ***************** ! DEF fn.output% ! head1$ = "; RICHARD WITTENOOM AND ASSOCIATES PTY LTD" head2$ = ";" + CR + LF + "; HDX: Hardy Cross Pipe Network Processing Utility" + CR + LF + ";" head3$ = "; iterations this run: " + num1$(num.its%) + CR + LF + ";" CALL PRINT.(.tf.out.chan%, head1$) CALL PRINT.(.tf.out.chan%, head2$) CALL PRINT.(.tf.out.chan%, head3$) ! CALL PRINT.(.tf.out.chan%, ("TITLE " + title$)) CALL PRINT.(.tf.out.chan%, ";") CALL PRINT.(.tf.out.chan%, ("COEFFICIENT " + num1$(pipe.coeff))) CALL PRINT.(.tf.out.chan%, ";") ! head2$ = "; loop pipe adj.loop diam (mm) q (litres/sec) length (m) Hl (m) delta q (%)" ! CALL PRINT.(.tf.out.chan%, ";") CALL PRINT.(.tf.out.chan%, head2$) ! output the headings CALL PRINT.(.tf.out.chan%, ";") CALL PRINT.(.tf.out.chan%, "START LINES") CALL PRINT.(.tf.out.chan%, ";") ! !### ### ### ###.# ###.### ####.## ###.## ###.## ! 4 7 8 10 10 5 8 ! a$ = "###" b$ = "####.##" c$ = "###.###" d$ = "###.#" ! FOR I% = 1% to flow% CALL GET. (.flows.chan%, flowbuf$, I%) final.Q = itrn.val(offset% + 3%) q.sign = sgn(final.Q) final.Q = abs(final.Q) ! setup to avoid -ve arg in, exp expr'n K = ((1/(PI * (diam^2)/4.0E6)) / (0.849 * pipe.coeff * ((diam/4.0E3)^0.63)))^1.85 final.hl = K * q.sign * (final.Q ^ 1.85) * length IF final.q = 0 & THEN final.dq.percent = 0 & ELSE final.dQ.percent = (INT((itrn.val(offset% + 2%) * 10000) / itrn.val(offset% + 3%))) / 100 ! outrec$ = " " + format$(loop%, a$) + " " + format$(pipe%, a$) + & " " + format$(other.loop%, a$) + " " + & format$(diam, d$) + " " + format$((itrn.val(offset% + 3%) * 1000), c$) & + " " + format$(length, d$) + " " + & format$(final.hl, b$) + " " + & format$(final.dQ.percent, C$) ! CALL PRINT.(.tf.out.chan%, outrec$) ! NEXT I% ! CALL PRINT.(.tf.out.chan%, ";") CALL PRINT.(.tf.out.chan%, "END LINES") CALL PRINT.(.tf.out.chan%, ";") ! FNEND ! ! **************** fn.dump.array% *************** ! DEF fn.dump.array% ! its.done% = 0% x$ = "#.##########" ! WHILE its.done% < num.its% ! FOR fl.ow% = 1% to num.flows% CALL GET. (.flows.chan%, flowbuf$, fl.ow%) outrec$ = "" start% = its.done% * 3% fin% = start% + (.its.per.page% - 1%) * 3% + 2% fin% = (num.its% -1%) * 3% + 2% IF fin% > (num.its% -1%) * 3% + 2% outrec$ = outrec$ + format$(itrn.val(i%), x$) + " " for i% = start% to fin% CALL PRINT.(.log.chan%, outrec$) NEXT fl.ow% CALL PRINT.(.log.chan%, (CR + LF + CR + LF)) ! its.done% = its.done% + .its.per.page% ! NEXT ! FNEND ! ! **************** fn.dump.loopfile% *************** ! DEF fn.dump.loopfile% ! FOR fl.ow% = 1% to num.flows% CALL GET. (.flows.chan%, flowbuf$, fl.ow%) outrec$ = num1$(loop%) + " " + num1$(pipe%) + " " + & num1$(other.loop%) + " " + num1$(diam) + " " & + num1$(q.lit.sec) + " " + num1$(length) & + num1$(itrn.val(0%)) CALL PRINT.(.log.chan%, outrec$) NEXT fl.ow% ! FNEND ! ! ***************** fn.help% ******************* ! DEF fn.help% ! print\print\print print "HARDY CROSS PIPE NETWORK ANALYSIS PROGRAM" print "-----------------------------------------" print print "Input commands are:" print print "INFILE filename.ext ..specify the data file" print "OUTFILE filename ..supply a name which will" print " be used to create names" print " for work and output files" print "ITERATIONS number ..how many cycles required" print "DEBUG number ..sets up what is to be" print " written to a logfile" print " (range is 1 to 5)." print " ..program takes over" print "ECHO ..echo commands on screen" print "DO (or) GO ..execute the program" print "QUIT (or) EXIT ..terminate execution" print "HELP (or) ? ..print this message" print\print ! FNEND {BL:[101,5]FNSAW.B4S} {BL:[101,5]FNANSCHK.B4S} ! 32000 CALL CLOSE. (.loops.chan%) CALL CLOSE. (.flows.chan%) CALL CLOSE. (.tf.out.chan%) CALL CLOSE. (.log.chan%) ! 32767 END