MEX files (a note)


As of April 2013, this version of the documentation is no longer maintained; however, it is consistent with the last (now retired) version of CODAS processing that used Matlab. We no longer update or fix the Matlab processing code, but we will maintain the Matlab code that reads CODAS Matlab output. Although the notes refer to both Python and Matlab processing, none of the code here will be maintained. This (now retired) documentation and code will remain available for awhile longer.

Python processing code is actively maintained and developed, and CODAS Python processing is documented here.

We use a mex file (“C” code compiled for Matlab) for interpolation. In older versions of Matlab, linear interpolation was done by “table1.m”. It was quite slow, so we wrote a version in “C” that was much faster. Table1 has been deprecated for some time, and in newer versions of Matlab it will no longer run. The current matlab replacement is “interp1.m”, but it is still slower than our mex file.

The “C” code is called “table1_core.c” and the mex file is called by “table1.m”. Several versions of table1_core exist in the matlab directory, in directories called mex6* or mex7*.

Test procedure

In Matlab, type:

% add codas matlab programs to your path

% find out which version you are using
which table1_core

% test it
x = table1([1 2; 3 4], 2)

% comment: this should return a value of 3

Adding a new mex path

(1) It “just works”

  1. The file “mexpath” will try to add an appropriate mex directory.
  2. Test (above) to see if you can run “table1” as is. If so, you’re done.

(2) A version exists already, but you have to find it

  1. If the test fails, read “mexpath.m” to see which versions are present.
  2. Choose a mex directory corresponding to a matlab version older than your own.
  3. change directories into that mex directory, and test again (the directory ”.” or “current working directory” should already be on your path).
  4. Test again.
  5. If you find a version that runs, copy the appropriate mex files to the “mexsrc” directory – it is the last thing “maxpath.m” will try, so in this scenario, “mexsrc” should be on your path.
  6. Kill matlab, start again, type “adcppath” and test table1.

(3)Nothing works; you have to make your own

  1. You must have a gcc compiler on your path

  2. in matlab, change directories to “mexsrc” and run

    mex table1_core.c
    %% these are used in our contouring routines
    mex arc.c
    mex polymx.c
    mex zgridmx.c
  3. Kill matlab, start again, type “adcppath” and test table1.