r"""Routines to create data from external modellers, for comparison purposes.

- DIPOLE1D: You must have Dipole1D installed and it must be in your system
  path; https://software.seg.org/2012/0003.

- EMmod: You must have Dipole1D installed and it must be in your system
  path; https://software.seg.org/2015/0001.

- Green3D: You must have Green3D installed (for which you need to be a member
  of the CEMI consortium). The following files must be in the folder
  `empymod/tests/green3d`: `green3d.m`, `grint.mexa64`,
  `grint.mexw64`,`normal.mexa64`, and `normal.mexw64`. Furthermore, you need
  Matlab.

Tested only on Linux (Ubuntu 16.04 LTS, x86_64).

Warning: These functions are to generate test-data with the provided scripts.
         They do not check the input, and are therefore very fragile if you do
         not provide the input as expected.

"""
import os
import subprocess
import numpy as np
from scipy.constants import mu_0
from os.path import join, dirname


class ChDir(object):
    r"""Step into a directory temporarily.

    Taken from:
    pythonadventures.wordpress.com/2013/12/15/
                    chdir-a-context-manager-for-switching-working-directories

    """

    def __init__(self, path):
        self.old_dir = os.getcwd()
        self.new_dir = path

    def __enter__(self):