%% plasiupd2.m is a modified version of plasiupd.m that allows
%% you to update a given day, if the following day file name
%% doesn't end with x. Basically useful when you have run
%% plasiupd.m and made a mistake with the first day to be 
%% updated.
%%

clear

dno=input('Day number? ');
year=input('Year? ');

%Calculate the new day number and year
[dnon,yearn]=daynum3(dno,year,1);
 
%Load in next days data set
yrs=int2str(yearn);
dns=int2str(dnon);
if dnon<10
 dns=['00',dns];
elseif dnon>=10 & dnon<100
 dns=['0',dns];
end
eval(['load d',yrs,'d',dns])
 
%Copy from next data days data set the required equatorial values
hyeqn=hyeq(:,1);
if hes==1
 heeqn=heeq(:,1);
end
oxeqn=oxeq(:,1);
   
%Load in current days data set
yrs=int2str(year);
dns=int2str(dno);
if dno<10
 dns=['00',dns];
elseif dno>=10 & dno<100
 dns=['0',dns];
end
eval(['load d',yrs,'d',dns,'x'])

%Update the required matrices
hyeq=[hyeq hyeqn];
if hes==1
 heeq=[heeq heeqn];
end
oxeq=[oxeq oxeqn];
  
%% Save the results
yrs=int2str(year);
dns=int2str(dno);
if dno<10
 dns=['00',dns];
elseif dno>=10 & dno<100
 dns=['0',dns];
end
if hes==1
 eval(['save d',yrs,'d',dns,' hytot hetot mlt lsh oxeq hyeq heeq MLTV LSHV tint nop lshcp gms sfs iricf hes sms'])
else
 eval(['save d',yrs,'d',dns,' hytot mlt lsh oxeq hyeq MLTV LSHV tint nop lshcp gms sfs iricf hes sms'])
end
 
%% Delete the original file
eval(['delete d',yrs,'d',dns,'x.mat'])
 