function [varargout]=ncattr(varargin)
fi=varargin{1};
if ~iscell(fi) error('files must be cell variables');	end
nmoors=length(fi);
if nargin==1		%this for attribute list info only
  disp('Global attributes for first file:')
  nc=netcdf(fi{1},'nowrite');
  atts=att(nc);
  for j=1:length(atts)
    disp(['	',name(atts{j})])
  end
  disp('Attributes for first variable:')
  vars=var(nc);
  vatts=att(vars{1});
  for j=1:length(vatts)
    disp(['	',name(vatts{j})])
  end
  close(nc)
  return
end

natts=nargin-1;
varargout={};
strval=[];
for i=1:nmoors
  nc=netcdf(fi{i},'nowrite');
  for k=1:natts
    val=[];
    attr=varargin{1+k};
    if iscell(attr)	%means there is also a "vari"
      vari=attr{2};
      attr=attr{1};
    end
    if ~isempty(findstr(attr,'dim'))
      dims=dim(nc);
      val=ncsize(dims{1});
    else
      atts=att(nc);	%global attributes
      for j=1:length(atts)
	if ~isempty(findstr(name(atts{j}),attr))
	  if ~strcmp(datatype(atts{j}),'char')
	    val=atts{j}(:);
	  else
	    if ~isempty(findstr(name(atts{j}),'tim'))
	      % find out boundaries between yr, mo, and day
	      tst = find( atts{j}(:) == '-');
	      % convert yr and day to numbers
	      if(~isempty(tst))
		yr = str2num(atts{j}(1:(tst(1)-1)));
		if yr<1900	yr=yr+1900;	end
		day = str2num(atts{j}((tst(2)+1):(tst(2)+2)));
		% convert month as roman numeral to integer
		mo = rom2num(atts{j}((tst(1)+1):(tst(2)-1)));
		val = [yr mo day];
		val=datenum(yr,mo,day);
	      else
		val = [9999 99 99];
		val=NaN;
	      end
	    else
	      strval=char(strval,atts{j}(:));
	    end
	  end
	  break
	end
      end
      
      if isempty(val)	%variable attributes 
	vars=var(nc); 
	vatts=att(vars{1}); 
	for j=1:length(vatts) 
	  if ~isempty(findstr(name(vatts{j}),attr)) 
	    if ~strcmp(datatype(vatts{j}),'char') 
	      val=vatts{j}(:); 
	    else 
	      strval=vatts{j}(:); 
	    end 
	    break 
	  end 
	end 
      end 
    end
    if isempty(strval)
      if length(val)==1
	varargout{k}(i)=val;
      else
	for j=1:length(val)
	  varargout{k}(j,i)=val(j);
	end
      end
    else
      varargout{k}(i)={strval};
    end
  end
  close(nc)
end

