function [field,x,y,z]=hopsgui_jslice(filein,jindex,time,var)

%       USAGE: [field,x,y,z]=hopsgui_jslice(filein,jindex,time,time)
%
% HOPS_JSLICE  Returns a matrix containing a vertical slice (field),
%   of the variable var  and the  position (y,z) 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
%		jindex = J index along which slice is taken
%
%  Pedro Velez (UIB), July 1999

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

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

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

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

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

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

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



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

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


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

if  strcmp('souvel',strrep(var,' ',''))
[temp,x,y,z]=hopsgui_jslice(filein,jindex,time,'temp');
[salt,x,y,z]=hopsgui_jslice(filein,jindex,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

y=getnc(filein,vargrid,[-1 1 1 2],[-1 1 1 2],1,1,2); %this is just a vector
x=getnc(filein,vargrid,[jindex -1 -1 1],[jindex -1 -1 1],1,1,2); %those are 2d matriz with the 
z=getnc(filein,vargrid,[jindex -1 -1 3],[jindex -1 -1 3],1,1,2); %vertical grid
field=getnc(filein,var,[time jindex -1 -1],[time jindex -1 -1],1,1,2);
field(find(field==0))=NaN;

 %The array is temp(tlat, tlon, outlev)
 %The array is x,y,z(tlat, tlon, outlev)
 
 %y(jindex) is the latitude of the longitudinal section in case of a 
 %non oblique domain


