%Function which runs IDL program cenergy.pro and outputs the name of the
%ascii file of all of the SSJ data for a particular day
function fileStr = createCenergyText(dateVec,sat)
global options
%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 config.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 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


       
