Functional for local and emr with output to text file