SUB HDDOUT(action$, title$, outfile$, num.node.recs%, num.pipe.recs%, num.loop.recs%) ! ! functions required by HDXDAT which are to be overlaid ! for task size reduction purposes ! {BL:[101,5]FCSERRCOM.B4S} {BL:[101,5]TRUTH.B4S} {HDDDEF.B4S} ! {HDDMAP.B4S} ! do% = fn.makeloops% IF action$ = "LOOPS" do% = fn.write.results% IF action$ = "RESULTS" ! SUBEXIT ! **************** fn.makeloops% **************** ! DEF fn.makeloops% ! CALL CLOSE.(.tf.out.chan%) ! in case it is already open CALL OPEN.(outfile$ + ".OUT", "W", .tf.out.chan%, 0%) ! do% = fn.output%(0%, 0%, 0%, 0%, 0) ! write out file headings ! for loop.index% = 1% to num.loop.recs% ! CALL GET.(.loop.chan%, loop$, loop.index%) do% = fn.setup.loop.recs%(loop.index%) IF loop% ! next loop.index% ! CALL PRINT.(.tf.out.chan%, ";") CALL PRINT.(.tf.out.chan%, ("END LINES " + CR + LF + ";")) ! CALL CLOSE.(.tf.out.chan%) ! FNEND ! ! ************** fn.setup.loop.recs%() ******************* ! DEF fn.setup.loop.recs%(lp%) ! note - the loop record is already in the loop buffer Collingwood% = NOT (history%) ! i2% = 0% WHILE (Collingwood% = (NOT (history%))) ! i.e. keep going more in hope than expectation ! l.node1% = l.node%(i2%) ! IF l.node%(i2% + 1%) & THEN l.node2% = l.node%(i2% + 1%) & ELSE l.node2% = l.node%(0%) & \ Collingwood% = history% ! i.e. set up to exit after this loop ! pipe% = fn.get.pipe%(l.node1%, l.node2%) ! IF l.node1% = node1% & THEN same.sense% = .true% ! sense% is +ve if the +ve & ELSE same.sense% = .false% ! direction is DOWNSTREAM ! ! same.sense% = true means that the positive direction (clockwise) ! in the loop is the same as that of the pipe itself as defined ! by node1% -> node2%. In this case the flow (+ or -) in the ! pipe is written into the record with the same sign. ! ! if not, the q is written into the record as -(q) ! IF same.sense% & THEN q.loop = pipeflow & ELSE q.loop = -(pipeflow) ! ! print "setup.loop.recs: calling OTL - loop: "; lp% CALL HDDOTL(l.node1%, l.node2%, oth.loop%, lp%, num.loop.recs%) ! print "setup.loop.recs: ret from OTL - oth loop: "; oth.loop% ! do% = fn.output%(1%, lp%, pipe%, oth.loop%, q.loop) ! i2% = i2% + 1% ! NEXT ! next pipe within the loop ! FNEND ! ! *********************** fn.get.pipe%() ******************* ! DEF fn.get.pipe%(nod1%, nod2%) ! get the required pipe record into the pipe buffer ! pipe.found% = .false% i1% = 0% WHILE ((i1% < num.pipe.recs%) AND (NOT(pipe.found%))) i1% = i1% + 1% CALL GET.(.pipe.chan%, pipe$, i1%) IF ((nod1% = node1%) AND (nod2% = node2%)) OR ((nod1% = node2%) AND (nod2% = node1%)) & THEN pipe.found% = .true% ! NEXT ! fn.get.pipe% = i1% ! FNEND ! ! *************** final Q, H and output ***************** ! DEF fn.output%(mode%, loop%, pipe%, other.loop%, sensed.q) ! IF mode% = 0% ! output initial headings & THEN head1$ = "; RICHARD WITTENOOM AND ASSOCIATES PTY LTD" & \ head2$ = ";" + CR + LF + "; HDD: Hardy Cross Pipe Network Data Preparation Utility" + CR + LF + ";" & \ CALL PRINT.(.tf.out.chan%, head1$) & \ CALL PRINT.(.tf.out.chan%, head2$) & \ head1$ = "TITLE" + HT + title$ & \ CALL PRINT.(.tf.out.chan%, head1$) & \ CALL PRINT.(.tf.out.chan%, ";") & \ head1$ = "COEFFICIENT " + num1$(pipe.coeff) & \ CALL PRINT.(.tf.out.chan%, head1$) & \ CALL PRINT.(.tf.out.chan%, ";") & \ CALL PRINT.(.tf.out.chan%, ("START LINES " + CR + LF + ";")) & \ head2$ = " loop pipe adj.loop diam (mm) q (litres/sec) length (m) " & \ head2a$ = "Hl (m) delta q (%)" & \ head2$ = head2$ + head2a$ & \ CALL PRINT.(.tf.out.chan%, (";" + head2$)) & \ CALL PRINT.(.tf.out.chan%, ";") & ! !### ### ### ###.# ###.### ####.## ###.## ###.## ! 4 7 8 10 10 5 8 ! IF mode% = 1% & THEN a$ = "###" & \ b$ = "####.##" & \ c$ = "###.###" & \ d$ = "###.#" & \ outrec$ = " " + format$(loop%, a$) + " " + format$(pipe%, a$) + & " " + format$(other.loop%, a$) + " " + & format$(diam, d$) + " " + format$(sensed.q, c$) & + " " + format$(length, d$) & \ CALL PRINT.(.tf.out.chan%, outrec$) ! FNEND ! ! *************** fn.write.results% ****************** ! DEF fn.write.results% ! CALL CLOSE.(.tf.out.chan%) CALL OPEN.(outfile$ + ".RES", "W", .tf.out.chan%, 0%) ! do% = fn.outnode%(0%, 0%) do% = fn.outnode%(1%, i1%) FOR i1% = 1% to num.node.recs% ! do% = fn.outpipe%(0%, 0%) do% = fn.outpipe%(1%, i1%) FOR i1% = 1% to num.pipe.recs% ! FNEND ! ! *************** write out node and head information ***************** ! DEF fn.outnode%(mode%, recc%) ! IF mode% = 0% ! output initial headings & THEN head1$ = "R I C H A R D W I T T E N O O M A N D AS S O C I A T E S P T Y L T D" & \ head1$ = head1$ + CR + LF + "------------------------------------------------------------------------------" & \ CALL PRINT.(.tf.out.chan%, head1$) & \ head1$ = CR + LF + title$ + CR + LF + CR + LF + "HARDY CROSS PIPE NETWORK ANALYSIS" & \ head2$ = CR + LF + CR + LF + "node elevation (m) residual head (m) consumption assigned (l/sec)" & \ CALL PRINT.(.tf.out.chan%, head1$) & \ CALL PRINT.(.tf.out.chan%, head2$) ! output the headings ! ! node% elevation (m) residual head (m) consumption assigned (l/sec) ! ### ###.## ###.### ###.## ! 7 3 4 ! IF mode% = 1% & THEN CALL GET.(.node.chan%, node$, recc%) & \ a$ = "###" & \ b$ = "####.##" & \ c$ = "###.###" & \ d$ = "###.#" & \ outrec$ = format$(recc%, a$) + " " + format$(elevation, b$) + & " " + format$(resid.head, c$) + " " + & format$(nodeflow, d$) & \ CALL PRINT.(.tf.out.chan%, outrec$) ! FNEND ! DEF fn.outpipe%(mode%, recc%) ! IF mode% = 0% ! output initial headings & THEN head1$=CR+LF+CR+LF+"pipe node 1 node 2 flow (l/sec) hydr. gradient velocity (m/s)" & \ CALL PRINT.(.tf.out.chan%, (head1$ + CR + LF + CR + LF)) ! ! pipe node 1 node 2 flow (l/sec) hydr. gradient velocity (m/s)" & ! ### ### ### ###.## #.#### ###.## ! IF mode% = 1% & THEN CALL GET.(.pipe.chan%, pipe$, recc%) & \ q = pipeflow/1000 ! convert to cu m/sec & \ q.sign = sgn(q) & \ qval = abs(q) ! setup to avoid -ve arg in, exp expr'n & \ K, veloc = 0 & \ veloc = q/(PI * (diam^2)/4.0E6) IF diam > 0 & \ K = ((1/(PI * (diam^2)/4.0E6)) / (0.849 * pipe.coeff * ((diam/4.0E3)^0.63)))^1.85 IF diam > 0 & \ hydr.grad = K * q.sign * (qval^1.85) & \ a$ = "###" & \ b$ = "####.##" & \ c$ = "###.###" & \ d$ = "#.######" & \ outrec$ = format$(recc%, a$) + " " + format$(node1%, a$) + & " " + format$(node2%, a$) + " " + & format$(pipeflow, c$) + " " + format$(hydr.grad, d$) & + " " + format$(veloc, c$) & \ CALL PRINT.(.tf.out.chan%, outrec$) ! FNEND ! SUBEND