File size distribution: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed wording in the output section comments.)
m (→‎{{header|REXX}}: made the output more consistant looking, added whitespace to the output, used a more idiomatic programming style..)
Line 420: Line 420:
fID=substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/
fID=substr(path, 1 + lastpos('\', path) ) /* " the filename and the filetype.*/
parse var fID fn '.' /* " just the pure filename of pgm.*/
parse var fID fn '.' /* " just the pure filename of pgm.*/
sw=linesize() - 1; if sw<80 then sw=79 /* " terminal width (linesize) - 1.*/
sw=max(79, linesize() - 1) /* " terminal width (linesize) - 1.*/
dirOut= fn".OUT" /*filename for workfile output of DIR.*/
dirOut= fn".OUT" /*filename for workfile output of DIR.*/
'DIR' ds '/s /-c /a-d >' dirOut /*do (DOS) DIR cmd for a data structure*/
'DIR' ds '/s /-c /a-d >' dirOut /*do (DOS) DIR cmd for a data structure*/
call linein 0, 1 /*open output file, point to 1st record*/
call linein 0, 1 /*open output file, point to 1st record*/
maxL=0 /*maximum length of number of records. */
maxL=0; @.=00; g=0 /*max len size; log array; # good recs.*/
@.=00 /*stemmed array to hold record counts. */
$=0 /*$: total bytes used by files found. */
g=0 /*number of good records found (so far)*/
do while lines(dirOut) \== 0 /*process data. */
$=0; do while lines(dirOut) \== 0 /*process data. */
_=linein(dirOUT); if left(_, 1)==' ' then iterate /*Not legit? Skip.*/
_=linein(dirOUT); if left(_, 1)==' ' then iterate /*Not legit? Skip.*/
parse upper var _ . . sz . /*uppercase suffix*/
parse upper var _ . . sz . /*uppercase suffix*/
Line 438: Line 437:
else L=length(sz) /*obtain the length of filesize number.*/
else L=length(sz) /*obtain the length of filesize number.*/
g=g + 1 /*bump the counter of # of good records*/
g=g + 1 /*bump the counter of # of good records*/
maxL=max(L, maxL) /*obtain the maximum length of filesize*/
maxL=max(L, maxL) /*get max length filesize for alignment*/
@.L=@.L + 1 /*bump counter of category of rec size.*/
@.L=@.L + 1 /*bump counter of record size category.*/
end /*j*/ /* [↑] categories: split by log ten.*/
end /*j*/ /* [↑] categories: split by log ten.*/


if g==0 then do; say 'file not found: ' ds; exit 13; end
if g==0 then do; say 'file not found: ' ds; exit 13; end /*no good records*/
say ' record size range count '
say ' record size range count '
hdr= '══════════════════ ═════════ '; say hdr; lenHdr= length(hdr)
hdr= '══════════════════ ══════════ '; say hdr; Lhdr=length(hdr)
mC=0 /*mC: the maximum count for any range.*/
mC=0 /*mC: the maximum count for any range.*/
do t=1 to 2 /*T==1 is used to find the max count.*/
do t=1 to 2 /*T==1 is used to find the max count.*/
do k=0 to maxL; mC=max(mC, @.k); if t==1 then iterate
do k=0 to maxL; mC=max(mC, @.k); if t==1 then iterate /*1st pass? */
select
select
when k==0 then y= ' zero '
when k==0 then y= center('zero', length( word(hdr, 1) ) )
when k==1 then y= ' 1 ──► 9 '
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1'
when k==2 then y= ' 10 ──► 99 '
end /*select*/
when k==3 then y= ' 100 ──► 999 '
say y || right( commas(@.k), 11) copies('─', max(1, (@.k / mC * sw % 1) - LHdr) )
when k==4 then y= ' 1000 ──► 9999 '
otherwise y= '10^'left(k-1,2) "──► 10^"left(k,2) '-1'
end /*select*/
say y || right(commas(@.k), 10) copies('─', max(1, (@.k / mC * sw % 1) - lenHdr) )
end /*k*/
end /*k*/
end /*y*/
end /*y*/
say
say
trace off; 'ERASE' dirOut /*perform clean─up (erase a work file).*/
trace off; 'ERASE' dirOut /*perform clean─up (erase a work file).*/
say commas(g) ' files detected,' commas($) " total bytes."
say commas(g) ' files detected, ' commas($) " total bytes."
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _</lang>
commas: parse arg _; do j#=length(_)-3 to 1 by -3; _=insert(',', _, j#); end; return _</lang>
This REXX program makes use of &nbsp; '''LINESIZE''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console) so as to maximize the width of the histogram.
This REXX program makes use of &nbsp; '''LINESIZE''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console) so as to maximize the width of the histogram.
<br>The &nbsp; '''LINESIZE.REX''' &nbsp; REXX program is included here &nbsp; ──► &nbsp; [[LINESIZE.REX]].<br>
<br>The &nbsp; '''LINESIZE.REX''' &nbsp; REXX program is included here &nbsp; ──► &nbsp; [[LINESIZE.REX]].<br>
Line 484: Line 479:
10^9 ──► 10^10 -1 1 ─
10^9 ──► 10^10 -1 1 ─


55,539 files detected, 12,656,593,862 total bytes.
55,539 files detected, 12,656,593,862 total bytes.
</pre>
</pre>


Line 501: Line 496:
10^7 ──► 10^8 -1 6 ─
10^7 ──► 10^8 -1 6 ─


20,385 files detected, 1,625,509,222 total bytes.
20,385 files detected, 1,625,509,222 total bytes.
</pre>
</pre>