function out=get_variable(var,name,diry,L);
% function out=get_variable(var,name,diry,L);
% this gets the variable of interst for the entire time, at the specified
% level, if 4D. If it is a 4D variable make sure and specify a level or you
% will run out of memory.
% name is the search string for collecting all the fiels with that search
% string (i.e. name = *his*)
%
%
%           Aaron Bever, updated May 2009

if nargin==3 | nargin ==4
    Fname=dir([diry,name]);
else
    diry = pwd;
    diry = [diry,'/'];
    Fname=dir([diry,name]);
end

if nargin==2 | nargin==3
out=[];
for j=1:length(Fname)
    disp(sprintf('file # %d',j))
    fname=[diry,Fname(j).name];
    d=nc_varget(fname,var);
    out=[out;d];
end

else
    out=[];
for j=1:length(Fname)
    disp(sprintf('file # %d',j))
    fname=[diry,Fname(j).name];
    S = get_varsize(fname,var);
    d=squeeze(nc_varget(fname,var,[0 L-1 0 0],[S(1) 1 S(3) S(4)]));
    out=[out;d];
end
end

