File size distribution: Difference between revisions

Added solution for Action!
(Ada version)
(Added solution for Action!)
Line 12:
Is your file system predominantly devoted to a large number of smaller files, or a smaller number of huge files?
<br><br>
 
=={{header|Action!}}==
DOS 2.5 returns file size in number of sectors.
{{libheader|Action! Tool Kit}}
<lang Action!>INCLUDE "D2:PRINTF.ACT" ;from the Action! Tool Kit
 
PROC SizeDistribution(CHAR ARRAY filter INT ARRAY limits,counts BYTE count)
CHAR ARRAY line(255),tmp(4)
INT size
BYTE i,dev=[1]
 
FOR i=0 TO count-1
DO
counts(i)=0
OD
 
Close(dev)
Open(dev,filter,6)
DO
InputSD(dev,line)
IF line(0)=0 THEN
EXIT
FI
SCopyS(tmp,line,line(0)-3,line(0))
size=ValI(tmp)
FOR i=0 TO count-1
DO
IF size<limits(i) THEN
counts(i)==+1
EXIT
FI
OD
OD
Close(dev)
RETURN
 
PROC GenerateLimits(INT ARRAY limits BYTE count)
BYTE i
INT l
 
l=1
FOR i=0 TO count-1
DO
limits(i)=l
l==LSH 1
IF l>1000 THEN l=1000 FI
OD
RETURN
 
PROC PrintBar(INT len,max,size)
INT i,count
 
count=4*len*size/max
IF count=0 AND len>0 THEN
count=1
FI
FOR i=0 TO count/4-1
DO
Put(160)
OD
i=count MOD 4
IF i=1 THEN Put(22)
ELSEIF i=2 THEN Put(25)
ELSEIF i=3 THEN Put(130) FI
RETURN
 
PROC PrintResult(CHAR ARRAY filter
INT ARRAY limits,counts BYTE count)
 
BYTE i
CHAR ARRAY tmp(5)
INT min,max,total
 
total=0 max=0
FOR i=0 TO count-1
DO
total==+counts(i)
IF counts(i)>max THEN
max=counts(i)
FI
OD
PrintF("File size distribution of ""%S"" in sectors:%E",filter) PutE()
PrintE("From To Count Perc")
min=0
FOR i=0 TO count-1
DO
StrI(min,tmp) PrintF("%4S ",tmp)
StrI(limits(i)-1,tmp) PrintF("%3S ",tmp)
StrI(counts(i),tmp) PrintF("%3S ",tmp)
StrI(counts(i)*100/total,tmp) PrintF("%3S%% ",tmp)
PrintBar(counts(i),max,17) PutE()
min=limits(i)
OD
RETURN
 
PROC Main()
DEFINE LIMITCOUNT="11"
CHAR ARRAY filter="H1:*.*"
INT ARRAY limits(LIMITCOUNT),counts(LIMITCOUNT)
 
Put(125) PutE() ;clear the screen
GenerateLimits(limits,LIMITCOUNT)
SizeDistribution(filter,limits,counts,LIMITCOUNT)
PrintResult(filter,limits,counts,LIMITCOUNT)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/File_size_distribution.png Screenshot from Atari 8-bit computer]
<pre>
File size distribution of "H1:*.*" in sectors:
 
From To Count Perc
0 0 2 0% ▌
1 1 20 3% █▌
2 3 44 8% ███▌
4 7 195 37% █████████████████
8 15 183 35% ███████████████▌
16 31 67 12% █████▌
32 63 6 1% ▌
64 127 0 0%
128 255 0 0%
256 511 0 0%
512 999 1 0% ▌
</pre>
 
=={{header|Ada}}==
Anonymous user