%% temppaw34.m is the last part (with temppaw35.m) of a heavily modified 
%% version of temppaw.m that plasimod(#).m uses to calculate the required
%% temperatures. 
%% temppaw32.m uses the mean day and night base temperatures and gradients 
%% values calculated by temppaw31.m temppaw33.m to determines the correct 
%% temperature for the given field lines depending on the local time.
%% temppaw34.m assumes the input is in the form where each row of the matrix
%% inputs corresponding to a seperate field line, with the remaining inputs
%% column vectors or scalars. The outputs matrices have the same format as
%% the input matrices.
%% temppaw34.m selects out the field lines that the user has specificed from the
%% global set. Only these field lines have the electron and ion temperatures
%% calculated.

function [tmpe,tmpi,tmpec,tmpic,tdiur,tdiurc]=temppaw34(poi,t0d,t0n,g0d,g0n,t0dc,t0nc,g0dc,g0nc,bh,dhr,lshv,long3,latg3,long3c,latg3c,dismat,latmatm,tmpn,tmpnc,timmat,dno,year)

% poi = logic vector which selects which field lines to calculate temperature for
% t0d = day base temperature (K)
% t0n = night base temperature (K)
% g0d = day gradient temperature (K/km)
% g0n = night gradient temperature (K/km)
% t0dc = conjugate day base temperature (K)
% t0nc = conjugate night base temperature (K)
% g0dc = conjugate day gradient temperature (K/km)
% g0nc = conjugate night gradient temperature (K/km)
% bh = bh parameter vector
% dhr = dhr parameter vector
% long3 = geographic longitude at 350km;
% latg3 = geographic latitude at 350km
% long3c = conjugate geographic longitude at 350km;
% latg3c = conjugate geographic latitude at 350km
% dismat = radial distances along field lines (km)
% latmatm = magnetic latitudes along field lines (rads)
% tmpn = neutral temperatures along field lines (K)
% tmpnc = conjugate neutral temperatures along field lines (K)
% timmat = UT (scalar)
% dno = day number (scalar)
% year = year (scalar)
%
% tmpi = ion temperatures at points of interest along field line(K).
% tmpe = electron temperatures at points of interest along field line(K).
% tmpic = ion temperatures at conjugate points of interest along field line(K).
% tmpec = electron temperatures at conjugate points of interest along field line(K).
% tdiur = diurinal parameter
% tdiurc = conjugate diurinal parameter

%Determine index of L-shells for which to determine electron and ion temperatures
sy=length(lshv);
sx=length(poi)/sy;
poim=reshape(poi,sy,sx);
[pyi,pxi]=find(poim==1);

%Calculate the required temperatures
[tmpe,tmpi,tmpec,tmpic,tdiur,tdiurc]=temppaw35(t0d(pyi),t0n(pyi),g0d(pyi),g0n(pyi),t0dc(pyi),t0nc(pyi),g0dc(pyi),g0nc(pyi),bh(pyi,:),dhr(pyi,:),lshv(pyi),long3,latg3,long3c,latg3c,dismat,latmatm,tmpn,tmpnc,timmat,dno,year);

