%ascii file of all of the SSJ data for a particular day
function fileStr = createCenergyText(datevec,sat)
global options
options.omni_source_path = '/hao/polar1/emery/aurora_i/xuw/combined_output/eln_tot_72_11_combnx7_hrly'; 
options.ssj_binary_path ='/hao/aim2/dmsp/dmsp_rich/dmspssj/';
options.omni_daily_path ='/hao/aim2/dmsp/omni/'; 
options.ssj_daily_path ='/hao/aim2/dmsp/dmsp_rich/dmspssjtxt/'; %THIS IS THE DESTINATION DIRECTORY FOR CENERGY OUTPUT
options.log_path ='/home/emery/reu11/';
options.script_path ='/home/emery/reu11/';
options.cenergy_path ='/home/emery/reu11/';
options.temp_path ='/home/emery/reu11/';
options.idm_source_path ='/hao/aim2/dmsp/dmsp_idm_4s/';

%options members: 
%omni_daily_path ssj_daily_path omni_source_path cenergy_path script_path 
%temp_path ssj_binary_path

    year = datevec(1); yearS = int2str(year);
    month = datevec(2); monthS = sprintf('%2.2d',month);
    day = datevec(3); dayS = sprintf('%2.2d',day);
    daynumber = dayno([year,month,day,0,0,0]);
    satS = int2str(sat);
    
    %Directories
    temp_path = options.temp_path;
    ssj_daily_path = options.ssj_daily_path;
    script_path = options.script_path;
    log_path = options.log_path;
    
    %Files
    
    fileStr = strcat('cenergy_all_f',satS,'_',yearS,monthS,dayS,'.txt');
    logStr = strcat(log_path,'cenergy_f',satS,'_',yearS,monthS,dayS,'_full.log');
    
    lastdayswitch=lastDayCheck(year, daynumber);
    
    cmd = sprintf('%sdocenergy.sh %i %i %i %i %i %i f13.txt',script_path, ...
        year, month, day, daynumber, sat, lastdayswitch);
    
    disp(cmd);
    exitstat = system(cmd);
    if (exitstat ~= 0)
        outstr = strcat('shell script exited with non-zero status check',logStr);
        disp(outstr)
    end

function out = dayno(datevec)
%lmk - Expects date vector format [YYYY MM DD 0 0 0]
dateNum = datenum(datevec)-datenum([datevec(1) 1 1 0 0 0]) + 1;
out = dateNum;

function yesno = lastDayCheck(year, daynum)
if ((mod(year,4) == 0)) %leap year
    switch daynum 
        case {31,60,91,121,152,182,213,244,274,305,335,366} 
            yesno = 1;
        otherwise
            yesno = 0;
    end
else %non-leap year
    switch daynum 
        case{31,59,90,120,151,181,212,243,273,304,334,365}
            yesno = 1;
        otherwise
            yesno = 0;
    end
end


       
