%% saccrd.m is designed to load in the JPL data file from
%% GFO and transfer the co-ordinates from ECI to geographic.
%%

function [tec,lonoe,latoe,disoe,longp,latgp,disgp,timmat,day,month,year,svn,tecbc]=saccrd(dnoi,yeari,dats)

% dnoi = day number of interest (scalar)
% yeari = year of interest (scalar)
% dats = data set of interest (0 = full, 1 = reduced)
%
% tec = observed TEC (TECU)
% snr = signal to noise ratio
% lonoe = geographic longitude of Oersted (rads)
% latoe = geographic latitude of Oersted (rads)
% disoe = radial distance of Oersted (km)
% longp = geographic longitude of GPS (rads)
% latgp = geographic latitude of GPS (rads)
% disgp = radial distance of GPS (km)
% timmat = UT time vector (hours)
% day = day vector 
% month = month vector
% year = year vector
% svn = GPS satellite SV number vector
% tecbc = GPS satellite TEC bias correction (TECU)

%Determine required year string
yrsi=int2str(yeari);
yrs=yrsi(3:4);

%Load in required file
if dats==0
 strn=['sacc_',yrs,'_',int2str(dnoi),'_eci_tec'];
else
 strn=['sacc_',yrs,'_',int2str(dnoi),'_eci_tec_60S'];
end
eval(['load jpl\',strn,'.dat -ascii'])
eval(['data=',strn,';'])

%Required TEC parameters
tec=data(:,8);
svn=data(:,9);
tecbc=data(:,10);

%Calculate the geographic co-ordinates of the satellites
[lonoe,latoe,disoe]=eci2geo(data(:,2),data(:,3),data(:,4),data(:,1),1);
[longp,latgp,disgp]=eci2geo(data(:,5),data(:,6),data(:,7),data(:,1),1);

%Remaining paramters
[timmat,dno,year]=timju2ut(data(:,1));
[day,month]=daynum2(dno,year);  
