/usr/share/psychtoolbox-3/PsychOneliners/NameBytes.m is in psychtoolbox-3-common 3.0.9+svn2579.dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | function bytesName=NameBytes(numBytes, abbreviateFlag)
% bytesName=NameBytes(numBytes [,abbreviateFlag])
%
% NameBytes accepts a quantity of bytes and returns a string naming that number
% of bytes in more readable form. For example:
%
% >> c=Screen('Computer');
% >> c.hw.physmem
%
% ans =
%
% 1.3422e+09
%
% >> NameBytes(c.hw.physmem)
%
% ans =
%
% 1.25 GB
%
% >>
%
% Numbers of bytes have the following names and abbreviations:
%
% Byte B 2^0 1
% KiloByte KB 2^10 1,024
% MegaByte MB 2^20 1,048,576
% GigaByte GB 2^30 1,073,741,824
% TeraByte TB 2^40 1,099,511,627,776
% PetaByte PB 2^50 1,125,899,906,842,624
% ExaByte EB 2^60 1,152,921,504,606,846,976
% ZettaByte ZB 2^70 1,180,591,620,717,411,303,424
% YottaByte YB 2^80 1,208,925,819,614,629,174,706,176
%
% By default NameBytes uses the abbeviated byte quantity label, for
% example "GB" instead of "GigaBytes". For the full name, pass
% 1 in the optional abbreviateFlag argument.
%
% see also: NameFrequency, DescribeComputer
% HISTORY
% 12/17/04 awi Wrote it to use in DescribeComputer. It is
% little more general than required for that
% purpose. An obvious extension would be to
% specify the number of places after the decimal.
%
byteNames={
'Bytes',
'KiloBytes',
'MegaBytes',
'GigaBytes',
'TeraBytes',
'PetaBytes',
'ExaBytes',
'ZettaBytes',
'YottaBytes'
};
byteNamesAb={
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
};
numByteNames=length(byteNames);
foundIndex=0;
for i=1:numByteNames
if round(numBytes/2^(10*(i-1)) * 100) / 100 < 1000
namesIndex=i;
foundIndex=1;
break;
end %if
end %for
if ~foundIndex
error('Failed to find a name for the value');
end
if nargin==2 && ~abbreviateFlag
bytesName=[sprintf('%3.2f', numBytes / 2^(10*(namesIndex-1))) ' ' byteNames{namesIndex}];
else
bytesName=[sprintf('%3.2f', numBytes / 2^(10*(namesIndex-1))) ' ' byteNamesAb{namesIndex}];
end %if ..else
|