function [img,header,tailer]=readimgarr(filename,nx,ny,N,type,head,tail,skip,ihead)
% readimgarr Read one image from a multifile image. 
% usage:: [img,header,tailer]=readimg(filename,nx,ny,N,precision,head,tail,skip,ihead) 
% 
% img is the Nth image in file filename which contains an array of
% images of size nx x ny.  Each pixel is read in as type precision (e.g.,
% 'char', 'uchar', etc).  
% 
% head is the length of file header in bytes and is returned as header.
% skip is a number of bytes to be skiped before the header and is *not* 
%   returned as header.
% tail is the length of file tailer in bytes and is returned as tailer.
% ihead is the length of an image header in bytes to be skipped befor each
%   image.  

% revision history:
% 08/11/96 Mark D. Shattuck <mds> readimgarr.m 

if nargin<=2 
  ny=nx;
  N=1;
  type='uint8';
  head=0;
  tail=0;
  skip=0;
  ihead=0;
elseif nargin<=3 
  N=1;
  type='uint8';
  head=0;
  tail=0;
  skip=0;
  ihead=0;
elseif nargin<=4
  type='uint8';
  head=0;
  tail=0;
  skip=0;
  ihead=0;
elseif nargin<=5
  head=0;
  tail=0;
  skip=0;
  ihead=0;
elseif nargin<=6
  tail=0;
  skip=0;
  ihead=0;
elseif nargin<=7
  skip=0;
  ihead=0;
elseif nargin<=8
  ihead=0;
end

size=nx*ny;

img=zeros(nx,ny);
[img(:) header tailer]=readraw(filename,size,type,head,tail,...
   (N-1)*(size+ihead)*sizeof(type)+skip+ihead);
img=img';

