function titleImageName = makeTitleImage(networkid, titleString, titleAxisPos, titleImageName)
%% ---------------------------------------------------------------------
% General:  Make a title with logo to be added to a any plot using something a = imadd(b,c)
% Input:    networkid
%           titleString {use a cell array for multiple lines, see title function}
%           titleAxisPos (optional)
%           titleImageName (optional)
% Output:   titleImageName - name of image file
% Modify Date/Author:  201207013, B.Biffard - see SVN history for revisions
%---------------------------------------------------------------------
%%check inputs
if nargin < 2
    titleString = [];
end
if nargin < 3
    titleAxisPos = [.1 .1 .85 .83];
end
if nargin < 4
    titleImageName = 'title_temp.png';
end
    
%%set up figure
f = figure;

%% place logo at the upper left corner of the figure window 
logopath = getNetworkLogoPath(networkid); 
[X,map] = imread(logopath);
colormap(map) % Sets colormap to that of the image
ha = axes('position',[0.13 0.93 0.21 0.07]);
hi = image(X); 
% make the axes invisible for the logo
set(ha,'Visible','off');
set(hi,'Visible','on');

%% add the title
hta = axes('Position',titleAxisPos);
xl = xlim;
yl = ylim;
htt = title(titleString,'FontSize',36,'HorizontalAlignment','right','position',[xl(2) yl(2)]);
set(hta,'Visible','off');
set(htt,'Visible','on');

%% annotate the time of plot generation
h3 = axes('Position',[0 0 1 0.82],'Visible','off');
set(gcf,'CurrentAxes',h3)
text(.99,.01,['Plot generated ',datestr(now),' UTC '],...
          'HorizontalAlignment','right','VerticalAlignment','bottom','FontAngle','italic','BackgroundColor','white','FontSize',32)

%% print and close
set(f,'PaperUnits','points','PaperPosition',[0 0 3300 2550],...
    'PaperPositionMode', 'manual','PaperOrientation','portrait','renderer','zbuffer');
print(f,'-dpng','-r71',titleImageName)
close(f)


