close all

% Use /dmsp_rich/dmspssj/blowupssj.sh for Liam's script to do whole year of SSJ cenergy.pro
% Matlab function datenum(V) uses a 6- or 3-element vector V (datevec) to return daynumber from 1 Jan 1800 or some other standard
%  There is no reverse daynumber to mm dd function(??)
% 6-element datevec = year month dayofmonth hour minute second 
 datevec = [2005 3 1 0 0 0]; %format: yyyy mm dd 0 0 0
%daynum001 = datenum([datevec(1) 1 1])
year = datevec(1);
%year = 2004;
hemisphere = 'S';
o = omniBox(year);
o.setfile
o.readyear
sat = 13; %j13 or j15 instrument
program = 1;
satS = sprintf('%2.2d',sat);
yearS = int2str(year);
idm_source_path=('/hao/aim3/dmsp/dmsp_idm_4s/Flag_Boundaries_Bz_all_');
idm_hem_year_bndy = strcat(idm_source_path,yearS,hemisphere,'.txt');

passstart1 = 0;
if program==3
% dayspec = [198 266 290 339 357];
% for n=1:5
dayspec = [105];
dayspec = [18];
% for n=1:1
%  daynum = dayspec(n);
%   for daynum=231:236
% Run out of java heap space with ~576 plots (NH 96001-265 for example) so do half year!
%    for daynum=88:212	% for F13 1995
% Only have 2005 days 1-90 ...w_Bin so can only do daynum=1:90 (unless run .f code!)
     for daynum=32:90
%     for daynum=1:181
%     for daynum=182:365
        [passstart1] = newCRB( o, year, daynum, sat, passstart1,hemisphere,idm_hem_year_bndy ); %run peakFlux Program
    end
% datevec is limited to 1 month - if use daynumber, can do 1 year
%   for k=datevec(3):31
%   for k=datevec(3):datevec(3)
%       close all
%       datevec(3) = k;
%       [passstart1] = newCRB( o, datevec, sat, passstart1 ); %run peakFlux Program
%   end
    disp('Main finished!')
else
  for k=datevec(3):2
%  for k=datevec(3):datevec(3)
     datevec(3) = k;
    dateVec = datevec;
%   createCenergyText2(dateVec,sat) %run Cenergy
    createCenergyText2(dateVec,sat,year) %run Cenergy to put .txt in dmspssjtxt/year/ directory
    disp('file generated')
  end
end
