%% plasiupd.m is the small script file that updates the data files
%% produced by plasimod.m to include the following day's timmat=0 
%% for the equatorial H+ and O+ values. This increases the size
%% of these matrices by one time value so that when used as lookup
%% tables they contain a 2400 value. The files produced by 
%% plasimod#.m which plasiupd.m loads in have 'c' as their last 
%% character. The modified data is saved in a file with the same 
%% name, but with the 'c' dropped. It then deletes the initial 
%% data file. Note that plasiupd cannot update the last file in 
%% the series specified by the user.
%%
%% 10/11/2001 - updated to include He+.
%% 5/3/2002 - remove different files name extension for IRI CCIR or URSI parameters (store iricf in arrays).
%% 5/3/2002 - He+ inclusion now optional. 
%% 9/3/2002 - now choose which version of MSIS model to use.
%%

clear

dnoi=input('Starting day number? ');
dnof=input('Final day number? ');
yeari=input('Starting year? ');
yearf=input('Final year? ');

z=1;
dno=dnoi;
year=yeari;

%Loop through each required file
while z
 %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,'x'])
 
 %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'])
 
 %% Update the name number and year, or break while loop if at end of run
 if dnon==dnof & yearn==yearf
  z=0;
 else
  dno=dnon;
  year=yearn;
 end
 
end 
