function gmt_map(sOutput, sPrefix, hAxes)
% function gmt_map(sOutput sPrefix, hAxes)
% ----------------------------------------
% Wrapper function for conversion of Matlab map-figures to GMT
%
% Input parameters:
%   sOutput         Filename without path information of the GMT script
%   sPrefix         Prefix of names of files generated by gmt_map (can contain path information)
%                   Default: empty string
%   hAxes           Handle of the axes for conversion (default: gca)
%
% Danijel Schorlemmer
% March 11, 2004

if ~exist('sPrefix', 'var')
  sPrefix = '';
end

if ~exist('hAxes', 'var')
  hAxes = gca;
end

gmt_init(hAxes, sOutput);

% Iterate thru the layers of the plot
vKids = get(hAxes, 'Children');
for nCnt = length(vKids):-1:1
  sType = lower(get(vKids(nCnt), 'Type'));
  switch sType
  case 'surface'
    [fXDiff, fYDiff] = gmt_pcolor(vKids(nCnt), sOutput, num2str(nCnt));
  case 'line'
    gmt_xy(vKids(nCnt), sOutput, num2str(nCnt));
  case 'text'
    gmt_text(vKids(nCnt), sOutput, num2str(nCnt));
  end
end

% Search for a colorbar and plot it
gmt_scale(hAxes, sOutput, '')

gmt_done(sOutput);

unix(['chmod u+x ' sOutput]);



