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

%       USAGE: [field,x,y,z]=hopsgui_kslice(filein,kindex,time,time)
%
% 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), July 1999


if strcmp('|Ut|',strrep(var,' ',''))
[u,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vtot');
[v,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vtot');
field=sqrt(u.^2+v.^2);
return;
end


if strcmp('|Ug|',strrep(var,' ',''))
[u,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vgeo');
[v,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vgeo');
field=sqrt(u.^2+v.^2);
return;
end


if strcmp('|Uc|',strrep(var,' ',''))
[u,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vclin');
[v,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vclin');
field=sqrt(u.^2+v.^2);
return;
end

if strcmp('ut',strrep(var,' ',''))
[field,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vtot');
return;
end

if strcmp('vt',strrep(var,' ',''))
[field,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vtot');
return;
end


if strcmp('ug',strrep(var,' ',''))
[field,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vgeo');
return;
end

if strcmp('vg',strrep(var,' ',''))
[field,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vgeo');
return;
end


if strcmp('uc',strrep(var,' ',''))
[field,x,y,z]=hopsgui_ksliceu(filein,kindex,time,'vclin');
return;
end

if strcmp('vc',strrep(var,' ',''))
[field,x,y,z]=hopsgui_kslicev(filein,kindex,time,'vclin');
return;
end


if  strcmp('potden',strrep(var,' ',''))
[temp,x,y,z]=hopsgui_kslice(filein,kindex,time,'temp');
[salt,x,y,z]=hopsgui_kslice(filein,kindex,time,'salt');
field=potden80(salt,potemp80(salt,temp,z),z);
return;
end

if  strcmp('souvel',strrep(var,' ',''))
[temp,x,y,z]=hopsgui_kslice(filein,kindex,time,'temp');
[salt,x,y,z]=hopsgui_kslice(filein,kindex,time,'salt');
field=svel80(salt,temp,z);
return;
end



if strcmp('pbar',strrep(var,' ',''))
disp(sprintf('>>>>This is a 2d variable, plotting temperature \n'));
var='temp';
end

if strcmp('qbar',strrep(var,' ',''))
disp(sprintf('>>>>This is a 2d variable, plotting temperature \n'));
var='temp';
end

vargrid='tgrid3';
if strcmp('wvsv',strrep(var,' ',''))
	vargrid='wvgrid3'
elseif strcmp('wvst',strrep(var,' ',''))
	vargrid='wtgrid3';
elseif strcmp('wvzv',strrep(var,' ',''))	
	vargrid='vgrid3';
end

x=getnc(filein,vargrid,[-1 -1 kindex 1],[-1 -1 kindex 1],1,1,2);
y=getnc(filein,vargrid,[-1 -1 kindex 2],[-1 -1 kindex 2],1,1,2);
z=getnc(filein,vargrid,[-1 -1 kindex 3],[-1 -1 kindex 3],1,1,2);
field=getnc(filein,var,[time -1 -1 kindex],[time -1 -1 kindex],1,1,2);
field(find(field==0))=NaN;


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