function jpgplot(fnum)

% Function jpgplot(fnum)
%
%    JPGPLOT enhances the line width and text settings on a plot ready for
%      export as a JPEG file.  Based around Janice Nelson's ENHANCE_PLOT
%      function.
%
%    jpgplot - changes the text setting of the title, xlabel, ylabel and,
%              if available, the legend, of the current figure to make them
%              more easily readable when exporting to a JPEG file.
%
%    jpgplot(fnum) - adjusts settings for the figure FNUM.
%
%    The Font/line settings are as follows:
%
%        Font: 'Times' (Default is 'Helvetica')
%        Font size: 14 (Default is 10)
%        Line width: 1 (Default is 0.5)
%        Marker size: 8 (Default is 6)

    if nargin > 1
        error('Can only specify one input variable: jpgplot(fnum)') ;
    end

    if nargin < 1
        fnum = gcf ;
    end

%    Set up variables for plot adjustment

    fontname = ('helvetica') ;
%    fontsize = 10 ;
%    linewid = 0.5 ;
%    markersiz = 6 ;
%    linewid = 1 ;
%    fontsize = 14 ;
    fontsize = 20 ;
    linewid = 2 ;
    markersiz = 15 ;
    tfontname = ('times') ;
    tfontsize = fontsize + 2 ;

%    Get plot ID data

    figax = get(fnum,'CurrentAxes') ;

    figx = get(figax,'XLabel') ;
    figy = get(figax,'YLabel') ;
    figt = get(figax,'Title') ;

%    Change plot settings

    set(figax,'LineWidth',linewid) ;
    set(figx,'fontname',fontname) ;
    set(figx,'fontsize',fontsize) ;
    set(figy,'fontname',fontname) ;
    set(figy,'fontsize',fontsize) ;
    set(figax,'fontname',fontname) ;
    set(figax,'fontsize',fontsize) ;
%    set(figax,'YaxisLocation','right') ;
%    set(figax,'YaxisLocation','left') ;
    set(figt,'fontname',tfontname) ;
    set(figt,'fontsize',tfontsize) ;
    set(figy,'VerticalAlignment','bottom') ;
    set(figx,'VerticalAlignment','cap') ;
    set(figt,'VerticalAlignment','baseline') ;

%    Change plot settings for children, if they exist

    figc = get(figax,'Children') ;
    n = length(figc) ;

    if n > 0

        typ = get(figc,'Type') ;
  
        for j = 1:n

            if strcmp('text',typ(j,:))
                set(figc(j),'fontname',tfontname) ;
                set(figc(j),'fontsize',fontsize) ;
            end

            if strcmp('line',typ(j,:))
                set(figc(j),'LineWidth',linewid) ;
                set(figc(j),'MarkerSize',markersiz) ;
            end

        end

    end

%           legend:     (Optional, DEF=0) if is 0, doesn't change the legend
%                       if is 1, changes only the lines on the legend
%                       if is 2, changes both the lines and the text
%                       if is 3, changes only the text

    legh = legend(figax) ;
    figc = get(legh,'Children') ;
    n = length(figc) ;
  
    if n > 0

        typ = get(figc,'Type') ;
    
        for j = 1:n

            if strcmp('text',typ(j,:))
                set(figc(j),'fontname',fontname) ;
                set(figc(j),'fontsize',fontsize-2) ;
            end

            if strcmp('line',typ(j,:))
                set(figc(j),'LineWidth',linewid) ;
                set(figc(j),'MarkerSize',markersiz) ;
            end

        end

    end

    figure(fnum) ;

    return

