function arcimage(filename, fignum)

H = findobj('Type','figure');
if isempty(H)
  disp('  ARCIMAGE Error (A figure must exist)')
  return
end

if nargin < 2
  fignum = gcf;
end

aH = findobj(fignum, 'Type', 'axes');

if length(aH) > 1
   disp(' ARCIMAGE warning (Multiple axes are present in the figure)');
   aH = min(aH);
end

% Set the units to normal
fUnits = get(fignum, 'Units');
aUnits = get(aH, 'Units');
set(fignum, 'Units', 'normal');
set(aH, 'Units', 'normal');

XLim = get(aH, 'XLim');
YLim = get(aH, 'YLim');
Position = get(aH, 'Position');

dX = diff(XLim);
dY = diff(YLim);

X = dX*Position(1)/Position(3);
Y = dY*(1 - (Position(4) + Position(2)))./Position(4);

Xtlc = XLim(1) - X;  % X Coordinate of top left corner in the same units as the plotted data
Ytlc = YLim(2) + Y;  % Y Coordinate of top left corner in the same units as the plotted data

width = dX/Position(3); % Width of figure in plotted axes units
height = dY/Position(4); % Height of figure in plotted axes units


% Return the unis to there original settings
set(fignum, 'Units', fUnits);
set(aH, 'Units', aUnits);

% Create JPG file name (a file format Matlab can create)
[p f e] = fileparts(filename);
if isempty(e)
  e = '.jpg';
end

if isempty(p)
   jpg = [f e];
   jgw = [f '.jgw'];
else
   jpg = [p filesep f e];
   jgw = [p filesep f '.jgw'];
end

print('-djpeg', jpg);
A = imread(jpg,'jpg');
[nXPixels, nYPixels, col] = size(A);

dx = width/nXPixels;
dy = height/nYPixels;

fid = fopen(jgw, 'wt');
fprintf(fid, '%16.14f\n', dx);
fprintf(fid, '%16.14f\n', 0);
fprintf(fid, '%16.14f\n', 0);
fprintf(fid, '%16.14f\n', dy*-1);
fprintf(fid, '%16.14f\n', Xtlc);
fprintf(fid, '%16.14f\n', Ytlc);
fclose(fid);