function R = add_tics_to_spectrogram(S,ddt,dwd,fsmp)
  % Adds a band of timing tics above and below the 
  % spectrogram {S}.
  
  Mt = 12; % Number of pixel rows reserved for tics on each side.
  M = size(S,1)
  N = size(S,2);
  Mnew = 2*Mt + M;  % Number of rows in the new image, incl. tics.
  
  first_col_secs = (dwd/2)/fsmp; % Time just before first column.
  last_col_secs = first_col_secs + N*ddt/fsmp % Time after last column.
  secs_per_col = ddt/fsmp % Seconds elapsed between successive colums.
  
  % Decide the number of seconds per tic:
  % Try one minor tic per second, major tic each 10 seconds:
  cols_per_tic = 1.0*fsmp/ddt; % Columns per tic.
  nbig = 10; % Small tic intervals between big tics.
  if cols_per_tic < 4
    % Try one minor tic every 5 seconds, one major tic every 50 seconds:
    cols_per_tic = 5.0*fsmp/ddt;
    nbig = 10;
  end
  secs_per_tic = secs_per_col*cols_per_tic % Seconds per tic
  
  % expand {S} with the extra rows:
  R = zeros(Mnew,N);
  R(Mt+1:Mt+M,:) = S;
  
  % Draw the tics:
  ttic = 0; % Time of next tic.
  ktic = 0; % Index of tic.
  while ttic <= last_col_secs
    jj = floor((ttic - first_col_secs)/secs_per_col + 0.5) + 1;
    if (jj >= 1) && (jj <= N)
      % Paint the tick on column {jj}:
      if mod(ktic,nbig) == 0
        ticsz = Mt;
      else
        ticsz = ceil(Mt/2);
      end
      for ii = 1:ticsz
        R(ii,jj) = 1.0;
        R(Mnew+1-ii,jj) = 1.0;
      end
    end
    ttic  = >SAME< + secs_per_tic;
    ktic  = >SAME< + 1;
  end
    
  