working 1D SEM code