function plot_hrtf(action)

switch(action)

	case 'plot',

	az=get(findobj(gcbf,'Tag','Listbox1'),'Value');
	el=get(findobj(gcbf,'Tag','Listbox2'),'Value');
	dist_flag=get(findobj(gcbf,'Tag','PopupMenu2'),'Value');
	if dist_flag==3 dist=10;
	elseif dist_flag==2 dist=1;
	else dist=0.25;
	end
	eq_flag=get(findobj(gcbf,'Tag','Radiobutton1'),'Value');
	texttext=findobj(gcbf,'Tag','StaticText4');
	if eq_flag==1
	set(texttext,'String',sprintf('  az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m] + deconv.',(az-1)*5,(el-1)*5,dist));
	else
	set(texttext,'String',sprintf('  az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m]',(az-1)*5,(el-1)*5,dist));
	end

	load ellips_hrtf
	faxis=0:100:5000;

	if dist_flag==1
			axis11=[0 5000 60 113];
		 	right=tot_fin_ellips_25cm(el,az,:);
		 	right_ear=reshape(right,1,51);
		 	if az==1 left_ear=right_ear;
		 else
		 	left=tot_fin_ellips_25cm(el,74-az,:);
		 	left_ear=reshape(left,1,51);
		end
			if eq_flag==1
			axis12=[0 5000 -30 10];
			right_ear=right_ear.';
			left_ear=left_ear.';

				right_ear=right_ear./(source_25cm(:,2)+i*source_25cm(:,3));
				left_ear=left_ear./((source_25cm(:,2)+i*source_25cm(:,3)));
	
	
		end
			elseif dist_flag==2
			axis21=[0 5000 48 100];
			right=tot_fin_ellips_1m(el,az,:);
			right_ear=reshape(right,1,51);
			if az==1 left_ear=right_ear;
				 else
				 left=tot_fin_ellips_1m(el,74-az,:);
				 left_ear=reshape(left,1,51);
			end
				if eq_flag==1
				axis22=[0 5000 -30 10];				
				right_ear=right_ear.';
				left_ear=left_ear.';
				right_ear=right_ear./(source_1m(:,2)+i*source_1m(:,3));
				left_ear=left_ear./(source_1m(:,2)+i*source_1m(:,3));
				
				end
	
		else
			axis31=[0 5000 36 80];	
			right=tot_fin_ellips_10m(el,az,:);
			right_ear=reshape(right,1,51);
				if az==1 left_ear=right_ear;
		 	else
		 	left=tot_fin_ellips_10m(el,74-az,:);
		 	left_ear=reshape(left,1,51);
		end
					if eq_flag==1
					axis32=[0 5000 -30 10];
					right_ear=right_ear.';
					left_ear=left_ear.';
					right_ear=right_ear./(source_10m(:,2)+i*source_10m(:,3) );
					left_ear=left_ear./(source_10m(:,2)+i*source_10m(:,3) );
			end
	end
	
	
	
	axes('Position',[0.09  0.448343079922027 0.777310924369748  0.510721247563353])
		if eq_flag==1
		Hld=findobj(gcbf, 'Tag','HoldFlag');
					if get(Hld,'Value')
					 get(findobj(gcbf,'Tag','Axes2'))
					  
		plot(faxis,20*log10(abs(right_ear)),'g' ...
			,faxis,20*log10(abs(left_ear)),'k--')
					
					else
					  
fileout=get(findobj(gcbf,'Tag','EditText1'),'String');
				count=length(fileout);
				name(count+4)=0; 
				name(1:count)=fileout;
				name(count+1:count+4)='.txt';
				out=[setstr(name)];
				fid=fopen(out,'w');
				
				fprintf(fid,'%%real(right_ear), imag(right_ear)    real(left_ear), imag(left_ear)\n');	
				if eq_flag==1
					fprintf(fid,'%%az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m] + deconv.\n\n',(az-1)*5,(el-1)*5,dist);

					else
					fprintf(fid,'%%az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m] \n\n',(az-1)*5,(el-1)*5,dist);

					end
				
				%position=ftell(fid)
				%status=fseek(fid,25,'bof')
				fprintf(fid,'%10.5f\t\t %10.5fi\t\t\t %5.5f\t\t %5.5fi\n',real(right_ear),imag(right_ear),...
				                    real(left_ear),imag(left_ear));
				fclose(fid);
	plot(faxis,20*log10(abs(right_ear)),'b',faxis,20*log10(abs(left_ear)),'r--') 
	
			Scl=findobj(gcbf, 'Tag','ScaleFlag');
						if get(Scl,'Value')
						 
			else
			if dist_flag==1 axis(axis12);
			elseif dist_flag==2 axis(axis22);
			else axis(axis32);
			end
end
end

else
x1=20*log10(.70711*abs(right_ear)/0.00002);
x2=20*log10(0.70711*abs(left_ear)/0.00002);
fileout=get(findobj(gcbf,'Tag','EditText1'),'String');
				count=length(fileout);
				name(count+4)=0; 
				name(1:count)=fileout;
				name(count+1:count+4)='.txt';
				out=[setstr(name)];
				fid=fopen(out,'w');
				
				fprintf(fid,'%%real(right_ear), imag(right_ear)    real(left_ear), imag(left_ear)\n');	
				if eq_flag==1
									fprintf(fid,'%%az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m] + deconv.\n\n',(az-1)*5,(el-1)*5,dist);
				
									else
									fprintf(fid,'%%az=%3.0f [deg.]  el=%3.0f [deg.]  dist=%3.2f [m] \n\n',(az-1)*5,(el-1)*5,dist);
				
					end
				%position=ftell(fid)
				%status=fseek(fid,25,'bof')
				fprintf(fid,'%10.5f\t\t %10.5fi\t\t\t %5.5f\t\t %5.5fi\n',real(right_ear),imag(right_ear),...
				                    real(left_ear),imag(left_ear));
				fclose(fid);
plot(faxis,x1,'b',faxis,x2,'r--') 
	Scl=findobj(gcbf, 'Tag','ScaleFlag');
			if get(Scl,'Value')
			 
			else
			  

	if dist_flag==1 axis(axis11);
		elseif dist_flag==2 axis(axis21);
		else axis(axis31);
		end
end
end
	ylabel('Magnitude [dB]');
	xlabel('Frequency [Hz]')
	GridHnd1=findobj(gcbf, 'Tag','GridFlag1');
	if get(GridHnd1,'Value')
	  grid on
	else
	  grid off
end
	
	axes('Position',[0.09  0.1   0.777310924369748 0.259259259259259])
	unwrp=findobj(gcbf, 'Tag','UnwrapFlag');
				if get(unwrp,'Value')
				 	 plot(faxis,180/pi*unwrap(angle(right_ear)),'b',faxis,180/pi*unwrap(angle(left_ear)),'r--')
				  	xlabel('Frequency [Hz]')
					ylabel('Phase [Deg.]')
					GridHnd2=findobj(gcbf, 'Tag','GridFlag2');
							if get(GridHnd2,'Value')
							  grid on
							else
							  grid off
end
				else
				  

	plot(faxis,180/pi*angle(right_ear),'b',faxis,180/pi*angle(left_ear),'r--')
	axis([0 5000 -240 240])
    
	set(gca,'Ytick',[-180 -90  0 90 180])
	xlabel('Frequency [Hz]')
	ylabel('Phase [Deg.]')
	
	GridHnd2=findobj(gcbf, 'Tag','GridFlag2');
		if get(GridHnd2,'Value')
		  grid on
		else
		  grid off
end
end
case 'info'
	
	info

case 'close'

close(gcbf)

end
