function [field,x,y,z]=oaggui_kslice(filein,kindex,time,var)

%       USAGE: [field,x,y,z]=oaggui_kslice(filein,kindex,time,var)
%
% HOPS_KSLICE  Returns a matrix containing a horizontal slice (field),
%   of the variable var and the  position (x,y) at a 
%   specified jindex and time step from an HOPS output (PE) file. 
%
%   In case of a non-oblique domain iindex represent a fixed longitude
% inputs: 	
% 		filein -- the .nc file
% 		time -- time of teh simulatio
%		var -- string with the variable name
%		kindex = k index along which slice is taken
%
% Pedro Velez (UIB-IEO), July 1999


if  strcmp('potden',strrep(var,' ',''))
[temp,x,y,z]=oaggui_kslice(filein,kindex,time,'temp');
[salt,x,y,z]=oaggui_kslice(filein,kindex,time,'salt');
field=potden80(salt,potemp80(salt,temp,-ones(size(temp)).*z),-ones(size(temp)).*z);
return;
end



x=getnc(filein,'grid2',[-1 -1 1],[-1 -1 1],1,1,2);
y=getnc(filein,'grid2',[-1 -1 2],[-1 -1 2],1,1,2);
field=getnc(filein,var,[time -1 -1 kindex],[time -1 -1 kindex],1,1,2);

depth=getnc(filein,'zout',[kindex 3],[kindex 3],1,1,2);
z=depth;

land=getnc(filein,'mask',[-1 -1],[-1 -1],1,1,1);
field(find(land==0))=NaN;
