function out=get_variable(var,name,pt,F2,diry);

%   function out=get_variable(var,pt,F,F2,diry);
%       long name - get me 3D or 4D a varaible at a given point
%
% This gets the variable of interst for the entire time, at the specified
% point. Set the F variable to correspond with the variable being three or
% 4 dimensions. It will loop through all the history files in the directory
% pulling out the values of the specified variable. "name" is the search
% string for finding all the files to loop through.
%
% F2 is a flag to display the file names as they are gotten to or not. One
% for yes, zero for no.
%
%   This also works for 1D variables as long as you put a place holder into
%   the pt variable
%
%   sample input
%       u=get_ptvariable('u',[108 8],1);
%
%       t=get_ptvariable('ocean_time',[],1);
%
%           Aaron Bever    2007, updated January 2009, May 2009

if nargin < 4
    F2 = 1;
end

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

S = get_varsize([diry,Fname(1).name],var);
F = length(S);

if(F==1)
    out=[];
    for j=1:length(Fname)
        if(F2)
            disp(sprintf('file # %d',j))
        end
        d=squeeze(nc_varget([diry,Fname(j).name],var));

        out=[out;d];
    end

elseif F==3
    out=[];
    for j=1:length(Fname)
        if(F2)
            disp(sprintf('file # %d',j))
        end
        S = get_varsize([diry,Fname(j).name],var);
        d=squeeze(nc_varget([diry,Fname(j).name],var,[0 pt(1)-1 pt(2)-1],[S(1) 1 1]));

        out=[out;d];
    end

elseif(F==4)
    out=[];
    for j=1:length(Fname)
        if(F2)
            disp(sprintf('file # %d',j))
        end
        S = get_varsize([diry,Fname(j).name],var);
        d=squeeze(nc_varget([diry,Fname(j).name],var,[0 0 pt(1)-1 pt(2)-1],[S(1) S(2) 1 1]));

        out=[out;d];
    end
else
    disp('Dimensions of variable must equal 1, 3, or 4')
end

