
% globals are declared in stn_udw.m
% global j_npts j_depth j_mean j_std outfile sub_title nplot;
editpdef                % turns off laTex interpreter for labels 

stn_U = [];
stn_V = [];
stn_W = [];
stn_ERROR_VEL = [];
stn_AMP_SOUND_SCA  = [];
stn_SPECTRAL_WIDT = [];
stn_PERCENT_GOOD = [];
stn_PERCENT_3_BEA = [];

if ~isempty(stn_file)
  eval(['load ' stn_file]);
  if exist('pstat_U')
    stn_U = pstat_U;
  end
  if exist('pstat_V')
    stn_V = pstat_V;
  end
  if exist('pstat_W')
    stn_W = pstat_W;
  end
  if exist('pstat_ERROR_VEL')
    stn_ERROR_VEL = pstat_ERROR_VEL;
  end
  if exist('pstat_AMP_SOUND_SCA')
    stn_AMP_SOUND_SCA = pstat_AMP_SOUND_SCA;
  end
  if exist('pstat_SPECTRAL_WIDT')
    stn_SPECTRAL_WIDT = pstat_SPECTRAL_WIDT;
  end
  if exist('pstat_PERCENT_GOOD')
    stn_PERCENT_GOOD = pstat_PERCENT_GOOD;
  end
  if exist('pstat_PERCENT_3_BEA')
    stn_PERCENT_3_BEA = pstat_PERCENT_3_BEA;
  end
end

pstat_U = [];
pstat_V = [];
pstat_W = [];
pstat_ERROR_VEL = [];
pstat_AMP_SOUND_SCA = [];
pstat_SPECTRAL_WIDT = [];
pstat_PERCENT_GOOD = [];
pstat_PERCENT_3_BEA = [];

if ~isempty(udw_file)
  eval(['load ' udw_file]);
end

nplot = 0;
if exist([outfile '.ps'])
  delete([outfile '.ps'])
end
if length(pstat_U) ~= 0 | length(stn_U) ~= 0 
  stnudwpl(stn_U, pstat_U, type_U, label_U, diff_U, 0)
end
if length(pstat_V) ~= 0 | length(stn_V) ~= 0
  stnudwpl(stn_V,pstat_V,type_V,label_V,diff_V,0)
end
if length(pstat_W) ~= 0 | length(stn_W) ~= 0
  stnudwpl(stn_W,pstat_W,type_W,label_W,diff_W,0)
end
if length(pstat_ERROR_VEL) ~= 0 | length(stn_ERROR_VEL) ~= 0
  stnudwpl(stn_ERROR_VEL,pstat_ERROR_VEL,type_ERROR_VEL,label_ERROR_VEL, ...
                    diff_ERROR_VEL,0)
end
if length(pstat_AMP_SOUND_SCA) ~= 0 | length(stn_AMP_SOUND_SCA) ~= 0
  stnudwpl(stn_AMP_SOUND_SCA,pstat_AMP_SOUND_SCA, ...
               type_AMP_SOUND_SCA,label_AMP_SOUND_SCA,diff_AMP_SOUND_SCA,1)
end
if length(pstat_SPECTRAL_WIDT) ~= 0 | length(stn_SPECTRAL_WIDT) ~= 0
  stnudwpl(stn_SPECTRAL_WIDT,pstat_SPECTRAL_WIDT, ...
               type_SPECTRAL_WIDT,label_SPECTRAL_WIDT,diff_SPECTRAL_WIDT,1)
end
if length(pstat_PERCENT_GOOD) ~= 0 | length(stn_PERCENT_GOOD) ~= 0
  stnudwpl(stn_PERCENT_GOOD,pstat_PERCENT_GOOD, ...
               type_PERCENT_GOOD,label_PERCENT_GOOD,diff_PERCENT_GOOD,2)
end
if length(pstat_PERCENT_3_BEA) ~= 0 | length(stn_PERCENT_3_BEA) ~= 0
  stnudwpl(stn_PERCENT_3_BEA,pstat_PERCENT_3_BEA, ...
               type_PERCENT_3_BEA,label_PERCENT_3_BEA,diff_PERCENT_3_BEA,2)
end
if rem(nplot, 4) ~= 0    % unfinished business
  eval(['print -append ' outfile])
end
