%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Name: plotCurrents.m
% Author: J. Kristoffer Hultgren
%
% Description:
%
% Plots currents as functions of time
%
% Input:  data  - Complete data set
%         ip    - Total current
%         ii    - Ion current
%         iph   - Photoelectron current
%         r     - Radius of orbit
%         ne    - Electron density
%
% Output: -
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function plotCurrents(data,ip,ii,iph,r,ne,Te)

global CO; % Global constants

Bx = data(:,9).*1e9;
By = data(:,10).*1e9;
Bz = data(:,11).*1e9;
B  = (Bx.^2 + By.^2 + Bz.^2).^(0.5);

P = 2*pi*sqrt(r^3/(CO.G*CO.M))/60/60; % Calculates the orbital period

figure('name','Timeplot Currents')

TH = linspace(0,360,max(size(data)));
subplot(2,1,1), plot(TH,ip,'r')
hold on
subplot(2,1,1), plot(TH,ii,'b')
grid on
subplot(2,1,1), plot(TH,iph,'g')
title('Hybrid')
legend('ip','ii','iph')
ylabel('I (nA)')
xlabel('\theta (grad)')
axes('position',[.13  .45  .775  .0001])
axis([0 P*40/36 0 0001])
xlabel('Time (h)')

figure('name','Timeplot electron parameters')

subplot(4,1,1), plot(TH,ip-ii,'g')
ylabel('I_{e} (nA)')
subplot(4,1,2), plot(TH,Te)
ylabel('T_{e} (eV)')
subplot(4,1,3), plot(TH,ne)
xlabel('\theta (grad)')
ylabel('n_{e} (cm^{-3})')
axes('position',[.13  0.2  .775  .0001])
axis([0 P*40/36 0 0001])
xlabel('Time (h)')

%Plot parameters used
figure('name','Parameters')
subplot(3,1,1), plot(TH,log10(Bx),'b')
title('Plasma Parameters')
hold on
subplot(3,1,1), plot(TH,log10(By),'g')
subplot(3,1,1), plot(TH,log10(Bz),'r')
ylabel('B-field log_{10}(nT)')
legend('B_{x}','B_{y}','B_{z}')
subplot(3,1,2), plot(TH,Te)
ylabel('Fluid temperature (eV)')
subplot(3,1,3), plot(TH,log10(ne))
hold on
plot(TH,log10(ip),'g')
legend('Fluid density log_{10}(cm^{-3})','I_{p} log_{10}(nA)')
xlabel('\theta (grad)')
