a new version by tang adding opening local source function