function [field,x,y,z]=hopsgui_islice(filein,iindex,time,var)

%       USAGE: [field,x,y,z]=hopsgui_islice(filein,iindex,time,time)
%
% HOPS_ISLICE  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
%		iindex = I index along which slice is taken
%
%  Pedro Velez (UIB), July 1999



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

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

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

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

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


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

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


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

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


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

if  strcmp('souvel',strrep(var,' ',''))
[temp,x,y,z]=hopsgui_islice(filein,iindex,time,'temp');
[salt,x,y,z]=hopsgui_islice(filein,iindex,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 1 1],[1 -1 1 1],1,1,1);
y=getnc(filein,vargrid,[-1 iindex -1 2],[-1 iindex -1 2],1,1,1);
z=getnc(filein,vargrid,[-1 iindex -1 3],[-1 iindex -1 3],1,1,1);
field=getnc(filein,var,[time -1 iindex -1],[time -1 iindex -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)

%x(iindex) is the longitude of the latitudinal section in case of a 
%non oblique domain

