%loads raw data into a matrix, across rows (TV raster scan order)
%
%Examples:
% X=loadraw('/mas/garden/flakes/steve/perspectivepics/red/data',203,320)
% X=loadraw('/mas/garden/flakes/steve/perspectivepics/red/data',203,320,'uchar')
%
%Types: char, schar,  short,  int,  long,  float, double,
%       uchar,        ushort, uint, ulong,
%       float32, float64, int8, int16, int32,
%       intN, uintN                               where 1 <= N <= 32

function [A,mycount] = easy_way_to_use_fread(myfilename,M,N,mytype);
if nargin==3
  mytype='uchar';
end%if
myint=fopen(myfilename);
if myint<0
  error('loadraw file read failed')
end%if
[Atranspose,mycount]=fread(myint,[N,M],mytype);
if mycount ~= M*N
  error(sprintf('loadraw: end of file reached before %g*%g=%g elements read',...
                M,N,M*N))
end%if

A=Atranspose.';
fclose(myint);  % need to close file; max number of open files appears to be 27

