1 SUB HDDOUT(action$, title$, outfile$, num.node.recs%, num.pipe.recs%, num.loop.recs%) 2 ! 3 ! functions required by HDXDAT which are to be overlaid 4 ! for task size reduction purposes 5 ! 6 COMMON (FCSERR) err1%, err2% 7 ! TRUTH.B4S 8 .DEFINE .TRUE%=-1% 9 .DEFINE .FALSE%=0% 10 ! {HDDDEF.B4S} 11 ! 12 .DEFINE .pipe.chan% = 21% 13 .DEFINE .node.chan% = 22% 14 .DEFINE .loop.chan% = 23% 15 .DEFINE .tf.out.chan% = 24% 16 .DEFINE .log.chan% = 25% 17 ! 18 ! 19 ! Constant definitions 20 ! 21 .DEFINE .eof% = -10% 22 .DEFINE .max.args% = 21% 23 .DEFINE .tf.bufsiz% = 128% 24 .DEFINE .cmd.line.siz% = 128% 25 .DEFINE .node.buf.siz% = 52% 26 .DEFINE .pipe.buf.siz% = 30% 27 .DEFINE .loop.buf.siz% = 42% ! must be (2 * .max.nodes% + 2) 28 ! 29 .DEFINE .max.nodes% = 20% 30 ! 31 ! {HDDMAP} 32 ! 33 ! buffers/maps 34 ! 35 MAP (NODES) node$ = .node.buf.siz% 36 MAP (NODES) n%(4%), ! connected nodes & ! -ve denotes blocked off & ! zero means no node & nodeflow, ! drawoff from node - litres/sec & xnode, ynode,! node coords & elevation, ! reduced level at node (m - AHD)) & resid.head, ! head at the node (m) & procflag% ! bit set means branch "done" 37 ! 38 MAP (PIPES) pipe$ = .pipe.buf.siz% 39 MAP (PIPES) node1%, node2%, diam, length, pipeflow 40 ! 41 ! note - pipeflow is +ve in direction node1 -> node2 42 ! 43 MAP (LOOPS) loop$ = .loop.buf.siz% 44 MAP (LOOPS) loop%, l.node%(.max.nodes%) 45 ! 46 MAP (INBUF) inbuf$ = 128% 47 MAP (CMDBUF) command.buffer$ = .cmd.line.siz% 48 ! 49 COMMON (SETUP) in.put%, input%, pipe.coeff, & node.file.open%, pipe.file.open%, & loop.file.open%, & echo%, first%, ask%, help%, & node.inp%, pipe.inp%, loop.inp%, line.inp%, & heads%, flows%, lo.op%, co.eff%, & loopdata%, results%, spare1%, & debug%, debug1%, debug2%, & more.data%, not.finished% 50 ! 51 ! 52 do% = fn.makeloops% IF action$ = "LOOPS" 53 do% = fn.write.results% IF action$ = "RESULTS" 54 ! 55 SUBEXIT 56 ! **************** fn.makeloops% **************** 57 ! 58 DEF fn.makeloops% 59 ! 60 CALL CLOSE.(.tf.out.chan%) ! in case it is already open 61 CALL OPEN.(outfile$ + ".OUT", "W", .tf.out.chan%, 0%) 62 ! 63 do% = fn.output%(0%, 0%, 0%, 0%, 0) ! write out file headings 64 ! 65 for loop.index% = 1% to num.loop.recs% 66 ! 67 CALL GET.(.loop.chan%, loop$, loop.index%) 68 do% = fn.setup.loop.recs%(loop.index%) IF loop% 69 ! 70 next loop.index% 71 ! 72 CALL PRINT.(.tf.out.chan%, ";") 73 CALL PRINT.(.tf.out.chan%, ("END LINES " + CR + LF + ";")) 74 ! 75 CALL CLOSE.(.tf.out.chan%) 76 ! 77 FNEND 78 ! 79 ! ************** fn.setup.loop.recs%() ******************* 80 ! 81 DEF fn.setup.loop.recs%(lp%) ! note - the loop record is already in the loop buffer 82 Collingwood% = NOT (history%) 83 ! 84 i2% = 0% 85 WHILE (Collingwood% = (NOT (history%))) ! i.e. keep going more in hope than expectation 86 ! 87 l.node1% = l.node%(i2%) 88 ! 89 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 90 ! 91 pipe% = fn.get.pipe%(l.node1%, l.node2%) 92 ! 93 IF l.node1% = node1% & THEN same.sense% = .true% ! sense% is +ve if the +ve & ELSE same.sense% = .false% ! direction is DOWNSTREAM 94 ! 95 ! same.sense% = true means that the positive direction (clockwise) 96 ! in the loop is the same as that of the pipe itself as defined 97 ! by node1% -> node2%. In this case the flow (+ or -) in the 98 ! pipe is written into the record with the same sign. 99 ! 100 ! if not, the q is written into the record as -(q) 101 ! 102 IF same.sense% & THEN q.loop = pipeflow & ELSE q.loop = -(pipeflow) 103 ! 104 ! print "setup.loop.recs: calling OTL - loop: "; lp% 105 CALL HDDOTL(l.node1%, l.node2%, oth.loop%, lp%, num.loop.recs%) 106 ! print "setup.loop.recs: ret from OTL - oth loop: "; oth.loop% 107 ! 108 do% = fn.output%(1%, lp%, pipe%, oth.loop%, q.loop) 109 ! 110 i2% = i2% + 1% 111 ! 112 NEXT ! next pipe within the loop 113 ! 114 FNEND 115 ! 116 ! *********************** fn.get.pipe%() ******************* 117 ! 118 DEF fn.get.pipe%(nod1%, nod2%) ! get the required pipe record into the pipe buffer 119 ! 120 pipe.found% = .false% 121 i1% = 0% 122 WHILE ((i1% < num.pipe.recs%) AND (NOT(pipe.found%))) 123 i1% = i1% + 1% 124 CALL GET.(.pipe.chan%, pipe$, i1%) 125 IF ((nod1% = node1%) AND (nod2% = node2%)) OR ((nod1% = node2%) AND (nod2% = node1%)) & THEN pipe.found% = .true% 126 ! 127 NEXT 128 ! 129 fn.get.pipe% = i1% 130 ! 131 FNEND 132 ! 133 ! *************** final Q, H and output ***************** 134 ! 135 DEF fn.output%(mode%, loop%, pipe%, other.loop%, sensed.q) 136 ! 137 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%, ";") & ! 138 !### ### ### ###.# ###.### ####.## ###.## ###.## 139 ! 4 7 8 10 10 5 8 140 ! 141 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$) 142 ! 143 FNEND 144 ! 145 ! *************** fn.write.results% ****************** 146 ! 147 DEF fn.write.results% 148 ! 149 CALL CLOSE.(.tf.out.chan%) 150 CALL OPEN.(outfile$ + ".RES", "W", .tf.out.chan%, 0%) 151 ! 152 do% = fn.outnode%(0%, 0%) 153 do% = fn.outnode%(1%, i1%) FOR i1% = 1% to num.node.recs% 154 ! 155 do% = fn.outpipe%(0%, 0%) 156 do% = fn.outpipe%(1%, i1%) FOR i1% = 1% to num.pipe.recs% 157 ! 158 FNEND 159 ! 160 ! *************** write out node and head information ***************** 161 ! 162 DEF fn.outnode%(mode%, recc%) 163 ! 164 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 165 ! 166 ! node% elevation (m) residual head (m) consumption assigned (l/sec) 167 ! ### ###.## ###.### ###.## 168 ! 7 3 4 169 ! 170 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$) 171 ! 172 FNEND 173 ! 174 DEF fn.outpipe%(mode%, recc%) 175 ! 176 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)) 177 ! 178! pipe node 1 node 2 flow (l/sec) hydr. gradient velocity (m/s)" & ! ### ### ### ###.## #.#### ###.## 179 ! 180 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$) 181 ! 182 FNEND 183 ! 184 SUBEND