function w_f = TimeStep(w_i, diff_op, a, dt, h, n, t, d_mid, DBC)

  global periodic;
    
  diff_source = diff_op*w_i;
  if(not(periodic)) % Add inhomogeneous BC term for left dirichlet boundary
      w0_beg=DBC(t); % Dirichlet BC at the beginning of the time step
      diff_source(1) = diff_source(1) +2*d_mid(1)/h^2*w0_beg;
  end
  
  adv_source = Fromm(w_i, a, dt, h, diff_source, n, t, DBC); % Use diffusion as a source
  if(not(periodic)) % Add inhomogeneous BC term for left dirichlet boundary
      w0_mid=DBC(t+dt/2); % Dirichlet BC at left at midpoint
      adv_source(1) = adv_source(1) + 2*d_mid(1)/h^2*w0_mid; 
  end
  
  w_f = CrankNicolson(w_i, diff_op, adv_source, dt);

end
